Somewhere in France
Hello, I made a procedure for a game which is used to stock some commands into one string, in order to make the data-writing easier to implement.
Here is the code :
procedure text(str st2)
'3 global vars (may be local)
b=0'where is the reading cursor in the string
c=0'what to do with the piece of text ?
for a=1 to str length(st2)' read each letter of the string
st1=st1+get char(st2,a-1)' stock the letter in the yet-read list
if mid str(st2,a,1)="•"' if the cursor encounters the symbol • then it means there is a 3-letters command right after it
st3=mid str(st2,a,4)' read the command
a=a+4' skip 4 letters
if st3="•job"' if the command is •job then say to the computer that the string that comes after will be put in the "job" var
if st3="•arg"' the same thing, with the var "money"
if st3="•say"' just display the following string
if st3="•giv"' give an item (the id of which is the string to be read)
if st3="•tak"' remove an item (same thing)
if st3="•snd"' play a sound of id=string to read
if st3="•end"' if the command is •end, then start to translate into real commands
if c=1 then job=as number(st1)' the job thing...
if c=2' the money thing...
if c=3' the print thing...
if c=6' the sound thing...
play sound as number(st1)
if c=4 and item[as number(st1)]=0' the give item thing... (please notice there are several items in my game, so I put them in an array)
play sound 2
if c=5 and item[as number(st1)]=1' the remove item thing.
c=0' OK, now prepare the procedure to read another command in the string (yes, you can put several things in one string).
Some examples of strings to input would be :
"•sayHey, that's 50 bucks !•end •arg50•end"
...this would display "Hey, that's 50 bucks !" and add 50 to the money var. (you can wisdraw money with this command.)
"•sayHuh, I just got a job as game-designer, I spent 23$ in a king-size pizza and I should whistle more often.•end •job3•end •arg-23•end •giv5•end •snd7•end"
...then, if 3 is the id for game-designer job, if 5 is the id for the pizza item and 7 the id for the whistling sound, the game will make all this at once !
I hope you'll find this piece of code useful. You can also add/custom stuffs (the job thing...) of course.
And think of the use of it if you want the player to input something he wants to be/happen in the game... Pretty useful for user-created contents, doesn't it ?