Log in

View Full Version : Using string names to represent variables



Cstrike
10-01-2010, 03:06 AM
I had a hard time naming this title, so let me just give the example of where I'm stuck.
I've been able to do this is in other coding programs, but don't know if it's possible in Simba:

Is it possible to have simba create a string, and then use the strings name as a variable:

EXAMPLE

var myString : String;
myInt : Integer;

//... down the road...

myString := 'myInt';
myInt := 5;

//... further down the road...

writeln (myString);
The output will read: myInt,

But I want the program to read the string as a variable name, or construct the name of the variable to make simba think that this is happening

writeln (myString);
** Now simba somehow reads the string inside as a variable name, which fools simba into thinking this:
writeln ((myInt));
**So simba thinks that it's doing
writeln (myInt);
**Then simba returns: 5



How this applies to me is, I'm making a bunch of TPoints for a tile walker for reflection [well, it's actually already made ;)], and I've set it up like this:
FALADOREASTBANK_X
FALADOREASTBANK_Y
VARROCKWESTBANK_X...etc, etc

So, if the user inputs something like

WalkTo ('VarrockWestBank');


I was wondering if there was a way I could modify the string to append on an "_X" and "_Y", and then use those as defining variables to grab the constant numbers? This would save me time from having to make a huge "case of..." list.

Or is this a bit farther than what is needed for Simba ;)?

NCDS
10-01-2010, 03:35 AM
IntToStr(); StrToInt(); ?

i luffs yeww
10-01-2010, 04:22 AM
^ To sum it up, ToStr();.

Feroc1ty
10-01-2010, 04:51 AM
Not sure if there are pointers in scar, but if there are you should look into that.

i luffs yeww
10-01-2010, 05:13 AM
Yes, they are, I think. And he specifically asked about Simba, and I think Simba has pointers.. Not sure though.

nielsie95
10-01-2010, 05:59 AM
No, this is impossible. The best thing you can do is indeed a case, or an array/TStringList. Also, Simba does indeed support pointers with the RUTIS interpreter.

Zyt3x
10-01-2010, 06:56 AM
The ToStr is not what he meant.

There is one way, but it includes saving all variable names to arrays and then do something like WriteLn(GetVariable_Int('VARROCK_WEST')); which would look in a TStringArray for the match and return the number in a TIntegerArray at the index it found the string in.

But I don't think it's worth it though... :p