Home   Help Search Login Register  

Author Topic: Converting variables from String to Int  (Read 864 times)

0 Members and 1 Guest are viewing this topic.

Offline Gadjuka

  • Members
  • *
  • Programmer
    • Operation Flashpoint: Commander
Converting variables from String to Int
« 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?
Currently working on Operation Flashpoint: Commander.
Website: http://www.nordserver.se/commander/

Offline DrStrangelove

  • Members
  • *
  • Mr.Creative
Re:Converting variables from String to Int
« Reply #1 on: 22 Oct 2002, 18:25:34 »
_newstring = format ["%1%2",_string,_i]

Does it work ?

Offline Gadjuka

  • Members
  • *
  • Programmer
    • Operation Flashpoint: Commander
Re:Converting variables from String to Int
« Reply #2 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
Currently working on Operation Flashpoint: Commander.
Website: http://www.nordserver.se/commander/

CareyBear

  • Guest
Re:Converting variables from String to Int
« Reply #3 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.

Offline Gadjuka

  • Members
  • *
  • Programmer
    • Operation Flashpoint: Commander
Re:Converting variables from String to Int
« Reply #4 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

Currently working on Operation Flashpoint: Commander.
Website: http://www.nordserver.se/commander/

CareyBear

  • Guest
Re:Converting variables from String to Int
« Reply #5 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)

Offline Gadjuka

  • Members
  • *
  • Programmer
    • Operation Flashpoint: Commander
Re:Converting variables from String to Int
« Reply #6 on: 02 Nov 2002, 11:37:49 »
You're right, it works!

Thanks a lot!!!
Currently working on Operation Flashpoint: Commander.
Website: http://www.nordserver.se/commander/