Home   Help Search Login Register  

Author Topic: Triggers or scripts? (Performance-wise)  (Read 1983 times)

0 Members and 1 Guest are viewing this topic.

Offline Dash5

  • Members
  • *
Triggers or scripts? (Performance-wise)
« on: 18 Jul 2007, 04:23:34 »
In a mission I'm currently working on, when the gunner of a static Dushka is killed, a replacement gunner takes his place. If the replacement is killed, someone replaces him. Right now I'm using triggers to accomplish this. That's 2 triggers x 6 gun emplacements. All the triggers do is check if the previous guy(s) is (are) dead and if the gun is still alive.

Would it be worth it to replace these triggers with scripts that do a check, say every two seconds instead of however often triggers check (how often is that?) or would the difference in performance would be negligible?
« Last Edit: 18 Jul 2007, 04:25:42 by Dash5 »

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: Triggers or scripts? (Performance-wise)
« Reply #1 on: 18 Jul 2007, 06:22:03 »
scripts r better dan trigers...... if u wanna help preformance on a laggy comp... i think dat functions r even better dan scripts... but its only worth it if da mision goes laggy... else do what is easy 4 u :D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline firecontrol

  • Members
  • *
Re: Triggers or scripts? (Performance-wise)
« Reply #2 on: 18 Jul 2007, 06:43:14 »
Right.

They check their conditions once every 0.5 seconds, by the way. I believe all at the same time (for editor placed ones.)
If you notice some jerkiness, or stuttering every half second... there are too many active triggers. :)

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Triggers or scripts? (Performance-wise)
« Reply #3 on: 18 Jul 2007, 07:58:25 »
I'm currently using General Barron's ManMG1.sqs script for this in ARMA.  I believe you can find it under scripts in the Editors Depot portion of this site.  (I was going to provide the link, but it appears the Editors Depot is not working at this moment.)
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re: Triggers or scripts? (Performance-wise)
« Reply #4 on: 18 Jul 2007, 13:34:10 »
I speak now for OFP, not ArmA, but I suspect it's much the same.

Triggers poll (check themselves) every 0.5 seconds or so if the condition field is "this".   Otherwise, they poll every frame.   Triggers themselves cause very little lag:  in other words it is possible to have a mission with a very large number of triggers.   What causes the problem is loons and wagons interacting with triggers, particularly if they are near the trigger boundary.   

Triggers are very powerful and sometimes wrongfully neglected by mission makers who are coders by hobby and therefore used to scripts.   In general you should start with triggers.

The thing to watch for in scripts is loops.   Fast loops eat resources.   I can't remember the fastest possible loop but there's no point in writing ~0.000001, it will still check every 0.05 or whatever the limit is.

The place where you can really get a benefit is when you really need something to be checked only every 5s, say.  In that case you're much better off with a script.   In this particular case, I'd leave it with the triggers  unless you have a large mission, in which case use the script.   
Plenty of reviewed ArmA missions for you to play

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Triggers or scripts? (Performance-wise)
« Reply #5 on: 18 Jul 2007, 13:48:50 »
Well, there where I can, I try to avoid the usage of triggers, unless they are mandatory to check the presence of something inside an area. The reason is quite simple, following what many triggers do from the editor is a total mess, it is much easier to follow what scripts do from the "old" Notead  :P

About performance, ArmA seems to be QUITE efficient with SQF scripts.

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Triggers or scripts? (Performance-wise)
« Reply #6 on: 18 Jul 2007, 19:23:19 »
hey Dash5,

Event handlers might work well if you are trying to check if a gunner or soldier in the game is killed. There's no script running in the background even at 5 second intervals or trigger running at 0.5 second intervals-- the script only runs if the guy is killed. 
Check this out from the COMREF: http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#addEventHandler

object addEventHandler handler
Operand types:
object: Object
handler: Array
Type of returned value:
Number or Nothing
Description:
Format of handler is [type,command].
Check scripting topic Event handlers for more information.
Index of currently added handler is returned.
Used In:
ArmA/OFP
Example:
player addEventHandler ["killed",{_this exec "playerKilled.sqs"}]

Offline Dash5

  • Members
  • *
Re: Triggers or scripts? (Performance-wise)
« Reply #7 on: 18 Jul 2007, 20:17:00 »
Hm. Event handlers seem like the best way to do this. Is there any trouble using 'killed' in an MP map?
« Last Edit: 18 Jul 2007, 20:21:53 by Dash5 »

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Triggers or scripts? (Performance-wise)
« Reply #8 on: 18 Jul 2007, 20:27:58 »
I don't know for multiplayer to be honest, maybe someone else does?  :dunno:

Offline T_D

  • CWR
  • **
  • Troubleshooting Device
Re: Triggers or scripts? (Performance-wise)
« Reply #9 on: 19 Jul 2007, 01:09:48 »
EH "killed" is local. So textoutput could be tricky.

Offline Dash5

  • Members
  • *
Re: Triggers or scripts? (Performance-wise)
« Reply #10 on: 19 Jul 2007, 08:12:59 »
Okay. Thanks for the advice all! I think I'll end up using a script in conjunction with EH.

where's that solved button???