Page 1 of 1

Nightwolf Productions's scripting tutorial

Posted: Thu Mar 05, 2009 11:10 pm
by Sunzoner

I'm quite a newbie in qbasic and wanted to find a quick and fast way to write a game that would run on user submitted scripts.

I was going through the Nightwolf Productions scripting tutorial (From QBtimes issue 1) when I realise there is no output to screen when I run the program.

The problem do not seem to be my windowxp's setting as I was able to "PRINT" to screen.

Does anyone have any idea what could have went wrong?

Posted: Fri Mar 06, 2009 1:58 am
by burger2227
SCRIPTS? What are you trying to do? Post some code...........and explain the objective.

Posted: Fri Mar 06, 2009 8:02 am
by Sunzoner
I was following the script in the QB times...

See the code below.

Code: Select all

OPEN "script.dat" FOR INPUT AS #1
  INPUT #1, ReadLine$
  ReadLine$ = LTRIM$(RTRIM$(ReadLine$))
  IF LEFT$(ReadLine$, 11) = "DISPLAYTEXT" THEN
   Temp1$ = RIGHT$(ReadList$, LEN(ReadLine$) - 12)
   PRINT Temp1$
  IF LEFT$(ReadLine$, 7) = "WAITKEY" THEN
  IF LEFT$(ReadLine$, 9) = "ENDSCRIPT" THEN
See script.dat below.

Code: Select all

DISPLAYTEXT Wow! This is my first scripting language!!
DISPLAYTEXT Press any key to end...
DISPLAYTEXT You pressed a key and now the program ends!
DISPLAYTEXT This action will NOT be executed because there 
DISPLAYTEXT is an ENDSCRIPT command before it!
What I wanted to do was to write a program which reads from a file and execute some orders, like in a pbem game. I stumble upon the QB times issue which teaches the use of scripts to read input and execute it.

Following the tutorial gives no errors. But I was not able to see any output in the screen when I "run" the code.

When I write:
PRINT "Hello World"
in the above code below "PRINT Temp1$" it works fine.

Posted: Fri Mar 06, 2009 1:51 pm
by burger2227
Try LINE INPUT #1, ReadLine$ and it should work. I gather you used PRINT #1 to create the file. LINE INPUT in both forms, creates a string variable. One with quotation marks on each end. So you need to use VAL for number values if you need them.

Also CLEARSCREEN would just use CLS

ENDSCRIPT could just end a program immediately with CLOSE: SYSTEM

CLOSE will close any OPEN files and, if not needed, can be used anyhow without an error.

SYSTEM allows a BAS file to run from the command line or a batch file without returning to the QB IDE. END or nothing at the end of the program will return to the IDE !

Also you could use INSTR(text$, search$) to find the print text start position and any Text to print. You search for a space after the Script command to find any print text. If 0 is returned, there is no space, thus no print command!

Code: Select all

SpacePosition% = INSTR(ReadLine$, " ")
IF SpacePosition% > 0 THEN 
   PrintPosition% = SpacePosition% + 1
   IF PrintPosition% < LEN(ReadLine$) THEN PRINT MID$(ReadLine$, PrintPosition%, (LEN(Readline$) - PrintPosition%) + 1)

Posted: Sat Mar 07, 2009 9:24 am
by Sunzoner
Thanks for all the suggestions.

I found out what was wrong with my code.

I should have used ReadLine$ instead of ReadList$ on line 6...

Will try the other suggestions when proceeding futher.

Thanks again for the suggestions.


Posted: Tue Mar 10, 2009 7:29 am
by iamdenteddisk
write a game in QB, who-du thunk it..

Re: Nightwolf Productions's scripting tutorial

Posted: Mon Nov 04, 2013 12:49 pm
by iamdenteddisk
I am using this same script method in a program and am wondering if anyone had any ideas on a script language it's self?

is there some standard it is better to follow?

I mean the example used DISPLAYTEXT to correspond to the qb print but the displaytext command could just as well be "wetdog"..

I see we have freedom, but is there a standardized group of "preferred" commands to use?