Hi all,
As I have been scripting for some months now I start to see the power of the "format" command. As I understood this command can turn variables into strings. However, i encounter some problems with it.
Example (there's no functional use for this... just the concept):
?(side player == west): _side = "W"
?(side player == east): _side = "E"
hint format ["%1 is sideplayer", _side]
Results in: a hint message saying "W is side player" if side is west, and "E is side player" if side is east.
To make scripts easier to write I want to use this concept in my scripts. I have on my MP map 3 AI helicopters for each east (e1, e2 and e3) and west team (w1, w2 and w3). Players can call them in for transport and I make a server-side script that checks availability of the choppers for assistance.
Note: my scripts are writen in such a way that if a chopper is in use the globalvariable chopperW1active (changing accordignto the name of the helicopter) "not isnull", but bears to identity of the player that is using it.
So, I was using this:
; player identity of requesting client is passed as variable into script
_player == _this select 0
?(side _player == west): goto "west"
?(side _player == east): goto "east"
#west
?(chopperw1active == objNull): chopperw1active = _player; PublicVariable "chopperw1active"
?(chopperw2active == objNull): chopperw2active = _player; PublicVariable "chopperw2active"
?(chopperw3active == objNull): chopperw3active = _player; PublicVariable "chopperw3active"
Hint "no choppers available"
exit
#east
?(choppere1active == objNull): choppere1active = _player; PublicVariable "choppere1active"
?(choppere2active == objNull): choppere2active = _player; PublicVariable "choppere2active"
?(choppere3active == objNull): choppere3active = _player; PublicVariable "choppere3active"
Hint "no choppers available"
exit
Result: no problem, scripts were functioning as they should.
Now, to make these scripts more elegant a was thinking of using the "format" command. Like this:
; player identity of requesting client is passed as variable into script
_player == _this select 0
?(side _player == west): _side = "W"
?(side _player == east): _side = "E"
?( format ["chopper%11active", _side] == objNull): format ["chopper%11active", _side] = _player; PublicVariable "format ["chopper%11active", _side]"
?( format ["chopper%12active", _side] == objNull): format ["chopper%12active", _side] = _player; PublicVariable "format ["chopper%12active", _side]"
?( format ["chopper%13active", _side] == objNull): format ["chopper%13active", _side] = _player; PublicVariable "format ["chopper%13active", _side]"
Hint "no choppers available"
exit
Result: as I do this I get to see an error message saying:
?(chopper1active == objNull)|#| generic error in expression
Can someone explain what I am doing wrong, or what the linitations are of the "format" command?
Thnx in advance,
Pimmelorus