Home   Help Search Login Register  

Author Topic: Condition count (array select array) prob  (Read 876 times)

0 Members and 1 Guest are viewing this topic.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Condition count (array select array) prob
« on: 22 Nov 2003, 00:39:17 »
Oh yes, this one is a big enigma as is the header. I have been stuck on it for 2 days now, after which I opened the bottle and gave up.

What I wan't to do is:
select an array of which any element meets a condition from an array of arrays. This might seem like a simple ({_x > 0} count array > 0) thingy, but no. I think I hit the bedrock of ofp code handling while digging into this. Here's the part of the script:

Quote
_initassets = ["AIRSTRIKE","ARTILLERY","MORTAR"]
.
.
.
_initairShells = [OFPTF_SPDlgbShells,OFPTF_SPDnapaShells,OFPTF_SPDclusterShells]
_initartyShells = [OFPTF_SPDartyShells,OFPTF_SPDartyFlares,OFPTF_SPDartySmokes]
_initmortShells = [OFPTF_SPDmortShells,OFPTF_SPDmortFlares,OFPTF_SPDmortSmokes]
_initassetshells = [_initairShells,_initartyShells,_initmortShells]

_as = 0
while "_as < (count _initassets)" do {if({_x > 0} count (_initassetshells select _as) > 0) then {stuff;};_as = _as + 1;};

So I think that would mean:
select array (from array of arrays) of which any element exceed 0. But no, gives me an error, expects number instead of the given array. After I find an array that meets the criteria I would add it into an array much similar to the array it is in already. With the exception that the new array only holds those which aren't entirely "empty", later I'll sort out the elements in the array withing the array to be accessed via buttons... But that is working already.

This is as elegant as I can get the code and it almost works. I've tried some other ways but they've never been as flexible as this would be. I hope some brainiac can help me or this will certainly be buried. So if you can see anything wrong with the "condition count" equasion, tell me and I'll be your slahve forever.  ;)
« Last Edit: 22 Nov 2003, 00:40:55 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:Condition count (array select array) prob
« Reply #1 on: 22 Nov 2003, 11:16:24 »
Hey !

*bows down before MI_FRED's renowned knowledge as an introduction*

I stumbled on your post this morning, and even though I'm no brainiac, I like to set my neurons working. I hence tried to test your script and here is what I have found :

What struck me at first is that you're counting  positive elements of arrays which look like weapons strings. So what I did was replace the "_initairShells", "_initartyShells", "_initmortShells" by random values, for instance :

Code: [Select]
_initairShells = [0,-1,0]
_initartyShells = [2,28,0]
_initmortShells = [54,-10,0]

I also inserted debugging hints :

Code: [Select]
while "_as < (count _initassets)" do {if({_x > 0} count (_initassetshells select _as) > 0) then {hint "yeah !"} else {hint "nope"};_as = _as + 1};
 And you know what ? It WORKED.

If the arrays contained only negative elements, I obtained "nope", if there was at least one positive element, "yeah !" showed.

I also tried your original script, only using the debugging hints and adding the "else" thing, and I had no error message, and simply kept having "nope".

Code: [Select]
while "_as < (count _initassets)" do {if({_x > 0} count (_initassetshells select _as) > 0) then {hint "yeah !"} else {hint "nope"};_as = _as + 1;};
So isn't there a simple mistake as to the NATURE of the elements counted (scalar values vs. strings) ? How can non-scalar values be superior or inferior to 0 ?

Anyway, Doc, I hope that all of this makes sense and that, well, it can be of any help.




Ig.


« Last Edit: 22 Nov 2003, 11:17:12 by Igor Drukov »

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Condition count (array select array) prob
« Reply #2 on: 22 Nov 2003, 13:06:08 »
Yea that was somewhat revealing. I've tried only counting one of the arrays inside _initassetshells at a time and that worked only when I counted one array. It worked regardless of wether or not the values are variables. But I do have to keep them as variables, as _initairShells for instance has the amounts left for use... this is for a dialog with which you can call support, and when the user has used up all OFPTF_SPDlgbShells for instance, it shouldn't be displayed in a button no more (that is done outside of the above script snippet).

All of the values in the arrays are set in init.sqs, and that way you can easily disable napalm by having the line 'OFPTF_SPDnapaShells = 0.'
They are all positive.

Thanks for debugging it for me  ;D I honestly didn't believe it would've worked. Well with my variable values it doesn't so we have to come up with some alternative way to use them.
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.