Home   Help Search Login Register  

Author Topic: Checking multiple arrays at the same time  (Read 803 times)

0 Members and 1 Guest are viewing this topic.

klavan

  • Guest
Checking multiple arrays at the same time
« on: 26 Nov 2005, 11:03:57 »
Hi all.
I need to know how it's possible to do this (and if it's possible).

To check if an array is empty I know I can use the following:
Code: [Select]
(format[{%1},arrayname] == {scalar bool array string 0xfcffffef})
But I've more than one array to be checked and I need to check 'em at the same time, but since I don't want to write a 1 kilometer lenght line,I've tried this:

Code: [Select]
(format[{%1 %2},arrayname1,arrayname2] == {scalar bool array string 0xfcffffef})
But it doesn't works.......
Any hint?

In addiction another question linked to the one above: how can I check the number of units in an array? I mean I need to know, for example, how many soldiers are store in a specific array.
Thank for the help.
Klavan


 
« Last Edit: 26 Nov 2005, 11:04:29 by klavan »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Checking multiple arrays at the same time
« Reply #1 on: 26 Nov 2005, 11:32:16 »
Code: [Select]
(format[{%1},arrayname] == {scalar bool array string 0xfcffffef}) Does not check to see if an array is empty.  It checks to see if it exists, and not just arrays either.  That is the value of any undefined variable.

To check to see if an array is empty use:

If (count arrayname < 1) then {it's empty} else {It is not empty}

This answers your second question also.

For multiple arrays try:

If (count (arrayname1 + arrayname2 + arrayname3 +... ) < 1) then {They are all empty} else {At least one of them is not empty}

Not tested.
« Last Edit: 26 Nov 2005, 11:34:51 by THobson »

klavan

  • Guest
Re:Checking multiple arrays at the same time
« Reply #2 on: 26 Nov 2005, 11:56:56 »
I cant get it to work.
Here's the script:

Code: [Select]
_1 = list Ts1
_2 = list Ts2
_3 = list Ts3
_4 = list Ts4
_Tot = _1+_2+_3+_4
player removeaction fl

? count units group player == 4 && ((count _1) <1): []exec "flare\Repeat.sqs"; exit
? count units group player == 4 && ((count _2) <1): []exec "flare\Repeat.sqs"; exit
? count units group player == 4 && ((count _3) <1): []exec "flare\Repeat.sqs"; exit
? count units group player == 4 && ((count _4) <1): []exec "flare\Repeat.sqs"; exit

{[_x] exec "flare\flaretrap.sqs"} foreach _tot

~8
"2" objstatus "Done"
Signals=true
exit

I didn't receive any error msg but the script ignores the lines and continues to run 'till the end.
The arrays are created  by triggers and this script should check if someone leaves the area of one of them before to fire the flaretrap script, 'cos the launches must be syncronized.

By adding:
Code: [Select]
? count units group player == 4 && ((count _1+_2+_3+_4) <4): []exec "flare\Repeat.sqs"; exit I receive an error message, somenthing like:
Code: [Select]
count units group player == 4 && ((count _1+_2+#_3+_4) <4): []exec "flare\Repeat.sqs"; exit : generic error on expression
Klavan

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Checking multiple arrays at the same time
« Reply #3 on: 26 Nov 2005, 12:04:28 »
As a test try it without:
count units group player == 4 &&

You might need to use more brackets than you are, or put them in a different place

((count _1+_2+_3+_4) <4)

should be

(count (_1+_2+_3+_4) <4)

I am now going out for most of the day so I won't be able to respond quickly - perhaps others can help.

« Last Edit: 26 Nov 2005, 12:05:54 by THobson »

klavan

  • Guest
Re:Checking multiple arrays at the same time
« Reply #4 on: 26 Nov 2005, 12:19:25 »
Quote
As a test try it without:
count units group player == 4 &&
My problem is that i must know this value, since i want the player to be able to fire the flares even if his group is reduced by one due to casualties.

However I'm going to experiment a little more with your suggestions, even if in the meanwhile I've found another solution by using a global variable which value is determined by triggers set to "repeatedly".
The fact is that I don't like to use global variables when possible.

Have  a great day ;)
Thanks
Klavan

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Checking multiple arrays at the same time
« Reply #5 on: 26 Nov 2005, 14:11:33 »
Thanks.  I am back briefly.  I onlt meant to remove that pice of code to test what was left - with the intention of putting it back later.