OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Gadjuka on 22 Oct 2002, 16:24:25

Title: Converting variables from String to Int
Post 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?
Title: Re:Converting variables from String to Int
Post by: DrStrangelove on 22 Oct 2002, 18:25:34
_newstring = format ["%1%2",_string,_i]

Does it work ?
Title: Re:Converting variables from String to Int
Post by: Gadjuka on 22 Oct 2002, 23:51:58
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
Title: Re:Converting variables from String to Int
Post by: CareyBear on 27 Oct 2002, 11:33:48
Ya, you need to turn it back into a reference. Use forEach for that.

"_x setFlagTexture ""us_vlajka.pac""" forEach [_newString]

that should work.
Title: Re:Converting variables from String to Int
Post by: Gadjuka on 27 Oct 2002, 19:55:02
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

Title: Re:Converting variables from String to Int
Post by: CareyBear on 01 Nov 2002, 23:27:00
Whoops, sorry.

_i = 0
"Format [""flag%1 setFlagTexture {usa_vlajka.pac}"", _x] forEach [_x]" forEach [_i]

Tested. Works. Gotta nest ur forEach statements.   8)
Title: Re:Converting variables from String to Int
Post by: Gadjuka on 02 Nov 2002, 11:37:49
You're right, it works!

Thanks a lot!!!