OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Gadjuka on 22 Oct 2002, 16:24:25
-
I'm making a script that changes the flagTexture of serveral flags and changes the color of several markers. The flags (and markers) are named flag0, flag1 and so on and therefore I need to convert a variable from a numerical value (_i = 2) to a string (_i = "2").
The script looks something like this:
_string = "flag"
_i = 0
#loop
;Something that convert _i from 0 to "0"
_newstring = _string + _i
;_newstring should be "flag0" but it doesn't work because _i
;isn't a string
_newstring setFlagTexture "rus_vlajka.pac"
_newstring setMarkerColor "ColorRed"
_i = _i + 1
etc...
goto "loop"
Anyone knows if this is possible or if there's a work-around?
-
_newstring = format ["%1%2",_string,_i]
Does it work ?
-
The "paste" part of it works, and the "pasted" string works with the setMarkerColor-command. But it doesn't seem to work with setFlagTexture, I get this error:
'_flag setFlagTexture "rus_vlajka.pac" |#|': Error setflagtexture: Type String, expected Object
-
Ya, you need to turn it back into a reference. Use forEach for that.
"_x setFlagTexture ""us_vlajka.pac""" forEach [_newString]
that should work.
-
Unfortunatly it still wants an Object!
I made a little test-script:
_i = 0
_flag = format["%1%2","flag",_i]
"_x setFlagTexture ""usa_vlajka.pac""" forEach [_flag]
But then I get the error message:
'_x setFlagTexture "usa_vlajka.pac"|#|': Error setFlagTexture: Type String, expected Object
-
Whoops, sorry.
_i = 0
"Format [""flag%1 setFlagTexture {usa_vlajka.pac}"", _x] forEach [_x]" forEach [_i]
Tested. Works. Gotta nest ur forEach statements. 8)
-
You're right, it works!
Thanks a lot!!!