SRL Archive - Help

Using string names to represent variables


Cstrike

2010-09-30 23:06:31

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

2010-09-30 23:35:56

IntToStr(); StrToInt(); ?

i luffs yeww

2010-10-01 00:22:49

^ To sum it up, ToStr();.

Feroc1ty

2010-10-01 00:51:15

Not sure if there are pointers in scar, but if there are you should look into that.

i luffs yeww

2010-10-01 01:13:51

Yes, they are, I think. And he specifically asked about Simba, and I think Simba has pointers.. Not sure though.

nielsie95

2010-10-01 01:59:59

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.

Gu3st...

2010-10-01 02:56:25

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