sub( and InString( are very very very useful commands for interacting with strings. Sub(String, start point, length) stores a substring of “String” starting at “start” for “length”. For example, sub(“12345”,3,1) will result in “3”, sub(“12345”, 3,3) will results in “345”, etc… By pairing sub( with the length of a string, you can also do some helpful things, like insert a character in a string, and shorten a string.
Say we have some String1 with the contents “1345”. This code;
Code: sub(Str1,1,1)+“2”+sub(Str1,2,3)->Str1
would store “12345” to Str1. This can be made to work universally;
Code: sub(Str1,1,X)+“2”+sub(Str1,X+1,length(Str1)-X+1)->Str1
would insert a “2” in a string after its X’th character.
InString( finds the location of a substring in another string. For example, if I want to find out where the string “34” appears in the string “12345”, I could just do InString(“12345”, “34”), which would simply store 3.
Now, by coupling InString with sub( and length(, you can do something like
Code: :inString(Str1,“1”)->X
:sub(Str1,1,X)+“2”+sub(Str1,X+1,length(Str1)-X+1)->Str1
which would add a “2” after the first “1” in a string. Thus, if String 1 was “134” to begin with, it would become “1234” after running that code. Running that code again would result in “12234”, and so on…
Anyways, my point was that you should have some degree of fluency with these commands before you start trying to write a full-fledged game. Though this is probably pushing it, try understanding how the following code works. Basically it’s a very simple program that creates a “character” that just moves around the screen .
Code: :ClrHome
:1->X
:1->Y
:While 1
:Output(Y,X,”O”
:Repeat Ans
:GetKey
:End
:Ans->A
:Output(Y,X,” “
:(A = 34) – (A =25) + Y ->Y
:(A = 26) – ( A = 24) + X -> X
:8(Y= 0) – 8 (Y = 9) + Y ->Y
:16(X = 0) – 16(X = 17) + X ->X
:End