OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Tyger on 27 Jan 2006, 00:27:12

Title: format command problems
Post by: Tyger on 27 Jan 2006, 00:27:12
Code: [Select]
call format[{"TYGAMMOBOX%1" = _ammobox},TYGBOXCOUNT]

Simply, why is that bit 'o code not working? TYGBOXCOUNT is predefined as 0 in the init.sqs, and _ammobox is a "ReammoBoxWest" created earlier in the script. I am trying to make a dynamic way for the user to spawn multiple ammo boxes, and give them each a global name so that they don't have to edit the script to add weapons and ammo to them.

The error that code produces is:
Code: [Select]
call format[{"TYGAMMOBOX%1" |#|= _ammobox},TYGBOXCOUNT]
Title: Re:format command problems
Post by: Terox on 27 Jan 2006, 00:41:57



_ammobox = call format["TYGAMMOBOX%1" ,TYGBOXCOUNT]
Title: Re:format command problems
Post by: Tyger on 27 Jan 2006, 00:54:55
Ay, but the problem with that is that _ammobox is the local variable of the ammobox. I am trying to store that local variable into a global variable. Yours would set teh local variable as the global, which as of yet ceases to have any value. :P

Sodding game ;D
Title: Re:format command problems
Post by: macguba on 27 Jan 2006, 01:00:03
call format [ {"TYGAMMOBOX%1"},TYGBOXCOUNT] = _ammobox

Just a guess.
Title: Re:format command problems
Post by: Tyger on 27 Jan 2006, 01:21:38
Garr. It doesn't work. The bleeding game.  :P
Title: Re:format command problems
Post by: Triggerhappy on 27 Jan 2006, 01:45:59
take out the quotes, you're setting a string equal to _ammobox, which is a no no  ;D

and then use your original code mac's won't work, nor will terox's
Title: Re:format command problems
Post by: General Barron on 27 Jan 2006, 09:24:09
Pardon my ignorance, but why are you bothering with all this format nonsense?

Why not just use a single array-type variable? ??? ??? ???

I would think that would be easier to deal with scripting-wise, and it would also save on global variables (too many of which can corrupt saved games).

Code: [Select]
TYGAMMOBOXES = TYGAMMOBOXES + [_ammobox]
The first ammo box is then (TYGAMMOBOXES select 0), the second one (TYGAMMOBOXES select 1), and so on.
Title: Re:format command problems
Post by: Tyger on 27 Jan 2006, 19:09:26
Quote
take out the quotes, you're setting a string equal to _ammobox, which is a no no

I was going for a global variable :P

@GB
Ah. Brilliant.  :D That will help a bunch.
Title: Re:format command problems
Post by: Fragorl on 27 Jan 2006, 20:21:14
You've already solved the problem, but just for posterity, the correct way is this:

Code: [Select]
call format[{TYGAMMOBOX%1 = _ammobox},TYGBOXCOUNT]

No extra quotes #EDIT as Triggerhappy pointed out.

Remember, the call command executes the contents of its string as though you had written that down, in your script, yourself. Sometimes it helps to hint out the string, read it in game and think to yourself 'If I wrote that exact code down in a script, would it work?'