Faster/Efficient Code

XeRo13g

New Member
Reaction score
3
Under the impression that the game continuously checks every trigger in the map, it's been a while that I'm converting triggers into functions. I have a trigger that runs every second through out the game and I've been adding more and more functions to it.

Is there anyone who is familiar with the inner workings of how the game reads the code?
What is best to use?

1. Have x additional & disabled triggers and use them with call TriggerExecute from the main trigger?

2. Only have the main trigger and add 5 functions above it while the main trigger only checks a condition to call them? Do those functions load each time the trigger runs?

I'm pretty sure that disabled triggers wouldn't be checked all the time but it's still something for the game to remember, let alone that many triggers can cause confusion.

Thanks in advance.-
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
its hard to help with a code when we cant see it :(
[noparse]
JASS:
[/noparse] please :)
 

luorax

Invasion in Duskwood
Reaction score
67
Since when do generic questions have codes? (except examples, but they're not necessary; all you need is imagination) or you simply scrolled down, noticed the lack of JASS tags and wrote that post?

However we never (or very,very rarely) use periodic triggers, so I didn't get the question either.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i requested that because i simply did not understand what he was requesting, which you obviously did not get either, so why flame?
 

XeRo13g

New Member
Reaction score
3
Apologies if I made no sense. I'll try to list it as an example.

1st way is to have 5 disabled triggers and call them like this:

JASS:
function Main_Trigger takes nothing returns nothing
if condition1==true then
call TriggerExecute(gg_trg_trigger1)
endif
if condition2==true then
call TriggerExecute(gg_trg_trigger2)
endif
if condition3==true then
call TriggerExecute(gg_trg_trigger3)
endif
if condition4==true then
call TriggerExecute(gg_trg_trigger4)
endif
if condition5==true then
call TriggerExecute(gg_trg_trigger5)
endif
endfunction


2nd way is by changing those triggers into functions and list them above the Main_Trigger:

JASS:
function function1 takes nothing returns nothing
do something
endfunction
function function2 takes nothing returns nothing
do something
endfunction
function function3 takes nothing returns nothing
do something
endfunction
function function4 takes nothing returns nothing
do something
endfunction
function function5 takes nothing returns nothing
do something
endfunction

function Main_Trigger takes nothing returns nothing
if condition==true then
call function1
endif
if condition==true then
call function2
endif
if condition==true then
call function3
endif
if condition==true then
call function4
endif
if condition==true then
call function5
endif
endfunction


I hope that makes sense.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
and what you have all of this on 1 event or a buncha different event type triggers all in 1 with a trillion conditions?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
uhmmm
i would do it with timers and seperate triggers saved in structs if you have a ton of them

but that may be wrong :/
 

Dirac

22710180
Reaction score
147
2. Only have the main trigger and add 5 functions above it while the main trigger only checks a condition to call them? Do those functions load each time the trigger runs?
This, also don't use [ljass]TriggerExcecute(trigger)[/ljass], the use of actions for trigger create leaks (the doom of GUI users), Conditions however are fine [ljass]TriggerEvaluate(trigger)[/ljass]
Remember that when you do this [ljass]TriggerAddCondition(trigger,boolexpr)[/ljass] it returns [ljass]triggercondition[/ljass] and after you can remove conditions from triggers using [ljass]TriggerRemoveCondition(trigger,triggercondition)[/ljass]
So if you wish to add/remove conditions to a trigger (instead of disabling them and check for conditions) do that.
 

XeRo13g

New Member
Reaction score
3
This, also don't use [ljass]TriggerExcecute(trigger)[/ljass], the use of actions for trigger create leaks (the doom of GUI users), Conditions however are fine [ljass]TriggerEvaluate(trigger)[/ljass]
Remember that when you do this [ljass]TriggerAddCondition(trigger,boolexpr)[/ljass] it returns [ljass]triggercondition[/ljass] and after you can remove conditions from triggers using [ljass]TriggerRemoveCondition(trigger,triggercondition)[/ljass]
So if you wish to add/remove conditions to a trigger (instead of disabling them and check for conditions) do that.

Helpful indeed, thanks.-
 

Dirac

22710180
Reaction score
147
I don't mean to be rude but do you just post to get your post-count high?
I'm going to state that GFreak's attitude does not suit this thread.
Don't post stuff you don't know about, neither ask for other people to test your theories.
Don't accuse another use of "flaming" because you don't understand what is being requested.
Besides that XeRo13g's post didn't ask for help with an specific code, he was just wondering which is the best way to take when dealing with a certain situation, and that was Luorax's complain to you.

Back to topic: Check out Nestharus's CTL library, the concept he uses for periodic timers (0.03125 timeout) is very similar to what you're dealing with (if you feel curious or still need more info on the matter)
 

XeRo13g

New Member
Reaction score
3
I will be checking out the library you suggested for future use. In this particular case, I'm using this main function that fires every 1 second for everything that doesn't really need high accuracy.

Thanks and +rep

PS. I've tried to find more about TriggerExecute and leak of actions but I couldn't. Can someone suggest an appropriate thread?
 

Dirac

22710180
Reaction score
147
It's more like common knowledge, the use of actions create leaks, just use conditions and you'll be fine.
A way to avoid having the function to [ljass]return boolean[/ljass] is to do the following
JASS:
function someFunc takes nothing returns nothing
endfunction

function onInit takes nothing returns nothing
    local code c=function someFunc
    call TriggerAddCondition(trig,Filter(c))
endfunction
 

Sevion

The DIY Ninja
Reaction score
424
Don't do this.

This is a million times slower than having individual triggers.

Regular triggers are way faster than this, just trust me on that.

There are other disadvantages of this method like the slow firing rate (which in itself can cause many more problems).

In short: Stick with regular triggers.
 

Dirac

22710180
Reaction score
147
Sevion you'll have to clarify your post.
Who are you talking to?
What do you mean by "regular triggers", if so, what type of triggers aren't regular.
To my eyes that post made no sense
 

Sevion

The DIY Ninja
Reaction score
424
I'm talking about the "I've already said that the main trigger runs every 1 second. That is the event."
 

Dirac

22710180
Reaction score
147
OP is trying to create a T32 like system with 1 second timeout, hes not trying to detect in-game events periodically
 

Sevion

The DIY Ninja
Reaction score
424
Apologies if I made no sense. I'll try to list it as an example.

1st way is to have 5 disabled triggers and call them like this:

JASS:
function Main_Trigger takes nothing returns nothing
if condition1==true then
call TriggerExecute(gg_trg_trigger1)
endif
if condition2==true then
call TriggerExecute(gg_trg_trigger2)
endif
if condition3==true then
call TriggerExecute(gg_trg_trigger3)
endif
if condition4==true then
call TriggerExecute(gg_trg_trigger4)
endif
if condition5==true then
call TriggerExecute(gg_trg_trigger5)
endif
endfunction


2nd way is by changing those triggers into functions and list them above the Main_Trigger:

JASS:
function function1 takes nothing returns nothing
do something
endfunction
function function2 takes nothing returns nothing
do something
endfunction
function function3 takes nothing returns nothing
do something
endfunction
function function4 takes nothing returns nothing
do something
endfunction
function function5 takes nothing returns nothing
do something
endfunction

function Main_Trigger takes nothing returns nothing
if condition==true then
call function1
endif
if condition==true then
call function2
endif
if condition==true then
call function3
endif
if condition==true then
call function4
endif
if condition==true then
call function5
endif
endfunction


I hope that makes sense.

According to this pseudocode and the OP, no he's not.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Trigger actions don't leak, destroying a sleeping trigger action does, where'd you get that idea anyway?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top