Home   Help Search Login Register  

Author Topic: Variables in unit names - possible?  (Read 587 times)

0 Members and 1 Guest are viewing this topic.

eurostorm

  • Guest
Variables in unit names - possible?
« on: 30 Jun 2003, 09:14:16 »
Basically I'm writing a script that is going through and checking all the units in my mission and seeing if they're alive or not so the camera will pan on a certain number of them if you win the mission.

Here's what's giving me trouble:

_unit=7
_variable=(GetDammage a_unit)


Basically I'm wondering if you can modify an object name in the script with variables. So where it says a(_unit), if _unit was 7, then it would say a7 and then check the damage of unit a7.  I just need it to put the value of the variable with a.  Is that  possible?

I know I can and will do all this easier using arrays instead of this method but for future reference I'd like to know if this is possible? Didn't see it used in any of the scripts I check or in the FAQ anywhere.

thanks




Offline Kuro

  • Former Staff
  • ****
  • 2./FschJgBtl 251 Green Devils
    • VBS2 Mission Download Site
Re:Variables in unit names - possible?
« Reply #1 on: 30 Jun 2003, 13:21:19 »
Hallo

to my knowleadge this is not possible. Beccause to solve such a statement, BIS had to implement recursive logic in there programming language. And that is IMHO a bit  to much work for a script langage.

Greatings Kuro

Offline TheCaptain

  • Members
  • *
  • You and The Captain Can Make it Happen
Re:Variables in unit names - possible?
« Reply #2 on: 30 Jun 2003, 14:18:18 »
Yes, this is in fact possible. I tried to do this a while back and eventually figured it out.

now, when you wrote getdammage a_unit, ofp thought the whole variable was a_unit, and didn't think unit was a variable name. So, waht we need ofp to do is compile the name via a string, and then "execute" the string.

So, off the top of my head, what I'd do is something like:

_unit=7    //Defines initial number
_string = "a" + format ["%1",_unit]    //Creates a string and turns the variable "_unit" into a string so it can be concatenated
_variable=(GetDammage call _string)  //gets the damage of the string by "executing" it with the call command. Call turns scripts into executable code.
hint format ["Damage to %1 = %2\n%3",_unit,_variable,_string] //gives you a sample output so you can see if all the variables are spiffy.
exit



This code worked fine on a unit I named "a7" in the editor.
The Captain

eurostorm

  • Guest
Re:Variables in unit names - possible?
« Reply #3 on: 30 Jun 2003, 20:22:39 »
Wow, very nice work. Never would've thought of it.

Thank you very much!