Author Topic: Text compare of a string of integers with corresponding numbers in loop counter  (Read 3504 times)

Songbird

  • Guest
Hi all,

Sorry for the block of code, I had to combine a bunch of commands just to test.  I've got a string that defines which commands should be executed (Incoming_Fire).  So in this case I would like to run the commands Abil0, Abil1 and Abil2.

The write commands after the for loop starts verifies that the values in the string (0 1 2) and the Loop counter values do show the same value when executing, but the Text Compare of Incoming_Fire containing Loop_Counter
Code: [Select]
Begin Text Compare : [{TXT:Incoming_Fire}] Contains [{TXT:{INT:Loop_Counter}}] doesn't give me the true result I'm expecting for Loop_Counter =0, Loop_Counter =1, and Loop_Counter =2.  I'm assuming it is a type mismatch of some kind, but I can't seem to figure out how to fix this.

Thanks in advance for the advice.

Kind regards,

Markus

Code: [Select]
Begin Boolean Compare : [Is_in_Space] Equals True
    Set Boolean [Red_Alert_State] to True
    Set Text [Incoming_Fire] to '0 1 2'
    Set Boolean [Incoming_Fire_State] to True
    Start Loop While : [Red_Alert_State] Equals True
        Play sound, '{VA_SOUNDS}\Star Trek sound\alert24.mp3'  (and wait until it completes)
        Begin Boolean Compare : [Incoming_Fire_State] Equals True
            Start Loop : Repeat From 0 to 22
                Write '[Red] {TXT:Incoming_Fire}' to log
                Write '[Blue] {INT:Loop_Counter}' to log
                Begin Text Compare : [{TXT:Incoming_Fire}] Contains [{TXT:{INT:Loop_Counter}}]
                    Execute command, '{Abil{INT:Loop_Counter}}' (by name) (and wait until it completes)
                    Write '[Green] Abil {INT:Loop_Counter}' to log
                End Condition
            End Loop
        End Condition
        Set Boolean [Incoming_Fire_State] to False
    End Loop
End Condition

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
It is because you are using a 'variable' variable name.  You will need to set an intermediary variable before doing your check.
You can *set* a 'variable' variable's value, but the condition comparison is overloaded to the point where you can't have a 'variable' variable.  If a token is used in the condition (in the variable name/token box), the rendered value is used in the comparison.

Example of using an intermediary variable:

Set integer [iterator] value to 0
Set Text [myVariable{INT:iterator}] to 'hello'
Set Text [myIntermediary] to [myVariable{INT:iterator}]
Write '{TXT:myIntermediary}' to log

This writes, 'hello' to the log.

I haven't gotten around to adding more (confusing lol) options to the conditions screen.  Again, it's currently overloaded to the point that it will need an option (something like, 'use variable variable names' yikes) to do what you are wanting without this type of workaround.

Songbird

  • Guest
Thank you very much Gary, it seems like a easy enough work around.  The feedback is much appreciated.