You might want to consider the string parsing tools of
INSTR() and MID$(). With these, you can separate a proper
string into it's relative parts. Then based in part on
what the string contains, you could make some decisions
about where values are to be assigned. For instance, if
a player's position was being defined by string data in a
text file, you might see something like this:
"p1:x=123.45,y=67.890,z=1023.56,e=525,m=23,t=17"
by using INSTR() to parse for "p", "x", "y", "z", "m", and "t", you can extract the values that follow with the
MI$() function, convert them to a value, and assign them
in a suitable manner:
player(1)\x=123.45
player(1)\y=67.89
player(1)\z=1023.56
player(1)\energy=525
player(1)\missles=23
player(1)\torpedoes=17
Not only can you easily control the number of players and
their capabilities by such tools, you can save partial
games in this manner to restart later, and you can add new
capabilities later if you like. For instance, you decide
you want to add shields, so you add s=200. If "s" for shields is not found in an existing player file, you can
arbitrarily give them a value, such as 100. Then later, when the game is saved, there will be a new category of
"s" so that any changes will become part of future play.
Not that the names of "player", "c", "y", and so on are
merely symbolic. The compiler understands them and makes
memory and register assignments that are consistent with
that symbol. The compiler understands that using "player(1)" will always mean the same reference when the program is created, and that "player(a)" would be the same as
"player(1)" when "a" has a value of "1". But these symbolic names are not a part of the program itself when it is created. So you cannot take a symbolic name, such as
"player", and put it into as string and expect that the program is going to recognize a relationship there. So saying something like "p1:" or "Player1:", in a string that
is accessed by your program, are equally valid (or just as
non-informative if you like). Either one can only be dealt with empirically with IF or SELECT statements, where you
create the decision making effort and tell the computer, via your program, how you want it to respond. A brief
example of what I mean:
While Not Eof(filein)
a$=ReadString$(filein)
b=Instr(a$,"p")
if b then idx=Val(Mid$(a$,b+1))
b=Instr(a$,"x=")
if b then player(idx)\x=val(Mid$(a$,b+2))
b=Instr(a$,"y=")
If b Then player(idx)\y=val(Mid$(a$,b+2))
;more breakouts here
Wend
Function Val#(parm$)
s#=parm$ ;force conversion from string form to float
return s# ;return the float value
End Function