Home   Help Search Login Register  

Author Topic: Help with "format" command  (Read 805 times)

0 Members and 1 Guest are viewing this topic.

Pimmelorus

  • Guest
Help with "format" command
« on: 05 Jun 2003, 10:47:49 »
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
« Last Edit: 05 Jun 2003, 10:52:36 by Pimmelorus »

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Help with "format" command
« Reply #1 on: 05 Jun 2003, 10:59:30 »
I don't know if what you are trying to do will work at all.   However, there is one immediate problem.   You have

chopper%11active

Assuming the format command is working here, the game is looking for the 11th element in your format array and there is only 1, so it is throwing up it's hands in horror.

Plenty of reviewed ArmA missions for you to play

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Help with "format" command
« Reply #2 on: 05 Jun 2003, 11:03:19 »
isnt dat MP editing ?

deres MP board around dis forums somwere ::) ;)

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Pimmelorus

  • Guest
Re:Help with "format" command
« Reply #3 on: 05 Jun 2003, 12:55:45 »
Nope, just a GENERAL question about the use of the format command. That I am working on a MP map is of lower importance.

Ok second thing is that when replacing the %11 for %1A (so with renaming the choppers) I still get the error message. Note that the error message is then:

?( format ["chopperAactive", _side] == objNull)|#| generic error in expression


the scripts reads no value for _side in the format-line. But when I put a hint line in the script that tells the value of _side using a format command the hint displays E just like it should.
« Last Edit: 05 Jun 2003, 13:07:04 by Pimmelorus »

deaddog

  • Guest
Re:Help with "format" command
« Reply #4 on: 05 Jun 2003, 16:22:57 »
The %1 in the format command has nothing to do with unit names.  It is the first parameter that you are passing to the format command.

Example
_a="Hello"
_b="deaddog"

hint format ["%1,my name is %2",_a,_b]

Will result in "Hello, my name is deaddog"

Quote
?( format ["chopperAactive", _side] == objNull)|#| generic error in expression

the scripts reads no value for _side in the format-line. But when I put a hint line in the script that tells the value of _side using a format command the hint displays E just like it should.

This is because you are passing no parameters to the format command.

Also, on a side note, the Publicvariable command does not work with strings, only numbers, boolean, object, or group.


Hope that helps.

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:Help with "format" command
« Reply #5 on: 05 Jun 2003, 16:37:57 »
Don't forget call.
Code: [Select]
_obj = call format ["unit%1", _i]
?not alive _obj : hint "Dead!!"
call format ["unit%1 setPos [0, 0, 0]", _i]
call format ["unit%1 = ""SoldierWB"" createUnit [[0, 0, 0], group player]", _i]
This way you can do stuff with named objects unit1, unit2, etc.

Doolittle

Pimmelorus

  • Guest
Re:Help with "format" command
« Reply #6 on: 06 Jun 2003, 08:07:27 »
ahhhhh, that might be it!. Can you give me some more info on that "call" command, the comref is just too unspecific. When do I use it? What does it mean?

Help would be appreciated.

Thnx,

Pimmelorus

Offline DrStrangelove

  • Members
  • *
  • Mr.Creative
Re:Help with "format" command
« Reply #7 on: 12 Jun 2003, 21:32:49 »
OMG i searched forever for this tip !

*hits forehead*  :P

THE CALL  COMMAND ! YAAAAA ...!!!