OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: eurostorm on 30 Jun 2003, 09:14:16

Title: Variables in unit names - possible?
Post by: eurostorm 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



Title: Re:Variables in unit names - possible?
Post by: Kuro 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
Title: Re:Variables in unit names - possible?
Post by: TheCaptain 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.
Title: Re:Variables in unit names - possible?
Post by: eurostorm on 30 Jun 2003, 20:22:39
Wow, very nice work. Never would've thought of it.

Thank you very much!