Results 1 to 7 of 7

Thread: Using string names to represent variables

  1. #1
    Join Date
    May 2007
    Location
    Everywhere
    Posts
    1,428
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Using string names to represent variables

    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
    Simba Code:
    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
    Simba Code:
    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 ?

  2. #2
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    IntToStr(); StrToInt(); ?

  3. #3
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    ^ To sum it up, ToStr();.

  4. #4
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

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

  5. #5
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  6. #6
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    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.
    Hup Holland Hup!

  7. #7
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •