Home   Help Search Login Register  

Author Topic: addaction format?!  (Read 511 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
addaction format?!
« on: 16 Mar 2004, 18:40:11 »
Is it possible to format a value in an addaction text?

e.g :

In the init.sqs :
Code: [Select]
retry = 5
Ingame the action should look like this :
Code: [Select]
Click here (x5)
Code: [Select]
;click.sqs

?retry == 0 : exit
retry = retry - 1

Blablabla...

Is there something like
ACT =player addaction format ["click here (x%1)",retry...???

What's the correct syntax?

thx in advance
« Last Edit: 16 Mar 2004, 18:43:11 by Blanco »
Search or search or search before you ask.

BibiPhoque

  • Guest
Re:addaction format?!
« Reply #1 on: 16 Mar 2004, 21:31:45 »
If that is possible, it would be more like :

player addaction [format ["click here (x%1)",retry], "click.sqs"]

But I didn't test that one :D

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:addaction format?!
« Reply #2 on: 16 Mar 2004, 22:06:43 »
Hey there  :wave: !


Code: [Select]
call format ["player addaction [""Click here %1"",""click.sqs""]",reply]

Ig.

Offline Blanco

  • Former Staff
  • ****
Re:addaction format?!
« Reply #3 on: 17 Mar 2004, 21:40:25 »
hi  :wave:
lol

It works perfect! :thumbsup:

I can delete half my script now, with that one line code, super!

But I don't understand that friggin' code... :P
Can you explain that call thing with a simple example, please...

thx again!

Search or search or search before you ask.

BibiPhoque

  • Guest
Re:addaction format?!
« Reply #4 on: 17 Mar 2004, 21:45:48 »
I guess the call command is used to execute code from text... With this you can format your code to whatever you want, then use the call command to execute it :

_command = "domove"
_code = "this "+ _command +" there"
call _code

Am I right?
« Last Edit: 17 Mar 2004, 21:46:13 by BibiPhoque »

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:addaction format?!
« Reply #5 on: 17 Mar 2004, 22:10:28 »
Hey !


I'll be honest, the association of "Call" and "Format" is to me one of the most powerful scripting combination in OFP.

You can do just about anything, especially things that you thought only possible with a limited number of elements. It can shorten scripts considerably, as you seem to have just experienced ;).

Now for the explanation (or its attempt  :P) :

"Call" executes the code that follows.

"Format" enables the inputting of a variable within a given string.

Combining both means that you execute a code within a string, code which may take into account varying numbers.


Here's a not too easy example :

Say you want the last unit of your squad (and him only) to move to your tent called "tent16", out of the twenty tents of the base.

Let's first create the tents, which we'll call "tent1" to "tent20". For this, let's just have a fire called "myfire" :

Code: [Select]
_i=1
#loop
call format ["tent%1=""campempty"" createvehicle [(getpos myfire select 0)+25*%1,getpos myfire select 1]",_i]
_i=_i+1
? _i<21 : goto "loop"
exit


Execute the code, and here we go ! 20 perfectly aligned open tents, named "tent1" to "tent20".


Now to our loon : regardless of the number of loons I have in my squad, I'll order him this :

Code: [Select]
call format ["(units group player select %1) commandmove getpos tent%2",(count units group player )-1,16]


And you can combine a potentially unlimited number of arguments...


Just another example, taken from my soon-to-be-released final version of WW2 Pathfinders (this is adverti...  :-X) :

Code: [Select]
call format ["ctrlsettext [120,""%1's Stick Status : (%2 active)""]",name player,count units group player]
With this, I update a dialog by showing the name of the player and displaying the exact number of loons in his squad.


Hoping that I have been clear enough, and that you can now behold the new unlimited horizons of this combination...


Regards,



Igor