Home   Help Search Login Register  

Author Topic: Multiple instances of one script or one monitoring global array?  (Read 1203 times)

0 Members and 1 Guest are viewing this topic.

Offline lendrom

  • Members
  • *
Sorry for non-informative topic title but I didn't know how to say what I want to ask in such a short sentence.
Suppose I'm writting a script which will run on a lot of units and the units which are affected by the script change many times durring the mission. I want to ask which is beter if it comes to performance:

Starting a new script that monitores a specified condition for every unit:
[_unit, _cover] exec checkForMovement.sqs
Code: [Select]
_unit = _this select 0
_cover = _this select 1
@ (not(currentCommand _unit in acceptableCommands)) OR not(alive _unit)
_unit setunitpos "auto"
?_unit HideBehindScripted false
IgnoreList = IgnoreList - [_cover]
exit

Or having one script that is running for the whole mission and has monitores every unit from a global array to which I add the unit:
UnitsToMonitor = UnitsToMonitor + [[_unit, _cover]]

Code: [Select]
acceptableCommands = ["STOP", "WAIT", "FIRE"]
#mainloop
;sending global variable to local to avoid unwanted interference from global space
_unitsToMonitor = UnitsToMonitor
_numOfUnits = count _unitsToMonitor
~0.01
? _numOfUnits == 0: goto "mainloop"

#subloop
_i = 0
_currentArray = _unitsToMonitor select _i
_currentUnit = _currentArray select 0
_currentCover = _currentArray  select 1
? not(currentCommand _currentUnit in acceptableCommands)) OR not(alive _currentUnit): _currentUnit setunitpos "auto"; _currentUnit HideBehindScripted false; IgnoreList = IgnoreList - [_currentCover]; unitsToMonitor = unitsToMonitor - [_currentArray]
~0.01
_i = _i + 1
? _i < numOfUnits: goto "subloop"
goto "mainloop"

The presented scripts can have some bugs because I wrote them straight at the forums but I wanted to ask about the principle. Is it better to have multiple instances of the first script or one script that monitors global array and runs during the whole mission?
Blessed are those who have nothing to say and yet they remain silent.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Basically you want to do the same in two ways, first in parallel and second in sequence. At first glance I would say the parallel mode would have a bigger impact in the performance if you have many many units, but the constant loop with only 0.01 delay time will be worse, and I understand that unless you have very few units you cannot increase that delay in the loop (#subloop).

Offline lendrom

  • Members
  • *
Thanks for your answer. I'm glad my explanation of the problem was understandable. Yes, I fear that in both cases the performance hit could be big but the I need to almost instantly know if the condition is met. And what I was thinking was if one quite fast loop would be better than many '@' conditions.
Blessed are those who have nothing to say and yet they remain silent.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
I don't know if it has changed for ArmA, but in OFP using an @ was better for performance than a very fast looping script, as long as the @ condition was simple which yours is.

If you are really worried about performance you should use sqf style scripting and the execVM command instead of sqs.
urp!

Offline lendrom

  • Members
  • *
That's interesting Mr. Peanut. Thanks for reply.
And about sqf. I'm trying to get used to it since OFP but I think my brain just works in a different way. Sqs is simply much more intuitive for me. And the only experience with programing I have is using PROLOG which is much different than enything else and is absolutely performance-unfriendly ;).
Blessed are those who have nothing to say and yet they remain silent.