Author Topic: Is it possible to use dynamic variables within expressions?  (Read 3222 times)

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Is it possible to use dynamic variables within expressions?
« on: January 29, 2017, 03:56:15 AM »
The {INT:Stored ships} variable in EDDI seems to be broken in 2.1.0 as it always evaluates to 'Not Set'. EDDI has shipyard variables such as {TXT:Stored ship n model} and where n is an integer for the stored ship. To get my own ship count, what I'm trying to do is this:

Set ShipCount = 0
Set x = 1
Loop while {EXP:{TXT:Stored ship x model} <> 'Not Set'}
  increment x by 1
  increment ShipCount by 1
End Loop

In the example above x represents a literal integer value as opposed to the letter 'x'. What I am trying to do is to make VoiceAttack evaluate the expression as the variable [Stored ship x model] as opposed to it coming out as literal text 'Stored ship x model' which never equals 'Not Set'.

I've already tried to build the variable name by setting a text variable which I change during the loop and also by building the variable name using concatenation. Actually, I'm not even sure you can use VoiceAttack in this manner. In any case, any further enlightenment on this issue would be greatly appreciated.
« Last Edit: January 29, 2017, 04:20:23 AM by mikelimtw »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Is it possible to use dynamic variables within expressions?
« Reply #1 on: January 29, 2017, 04:22:03 AM »
Code: [Select]
Set small int (condition) [ShipCount] value to 0
Set small int (condition) [x] value to 1
Start Loop While : [{EXP: '{TXT:Stored ship {SMALL:x} model}' <> 'Not Set'}] Equals '1'
Set small int (condition) [x] value as incremented by 1
Set small int (condition) [ShipCount] value as incremented by 1
End Loop
Write '[Purple] There are {SMALL:ShipCount} stored ships' to log

Or

Code: [Select]
Set small int (condition) [ShipCount] value to 0
Start Loop While : [{EXP: '{TXT:Stored ship {EXP:{SMALL:ShipCount} + 1} model}' <> 'Not Set'}] Equals '1'
Set small int (condition) [ShipCount] value as incremented by 1
End Loop
Write '[Purple] {SMALL:ShipCount}' to log

Or

Code: [Select]
Set small int (condition) [ShipCount] value to 1
Start Loop While : [{EXP: '{TXT:Stored ship {SMALL:ShipCount} model}' <> 'Not Set'}] Equals '1'
Set small int (condition) [ShipCount] value as incremented by 1
End Loop
Set small int (condition) [ShipCount] value as decremented by 1
Write '[Purple] {SMALL:ShipCount}' to log

mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: Is it possible to use dynamic variables within expressions?
« Reply #2 on: January 29, 2017, 08:22:11 AM »
Ok now I understand the logic of the syntax. I just couldn't for the life of me figure out the correct syntax for this. Everything works like a charm now! Thanks Pfeil!
« Last Edit: January 29, 2017, 08:54:53 AM by mikelimtw »