Faster/Efficient Code

XeRo13g

New Member
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.-
 

luorax

Invasion in Duskwood
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.
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
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.
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.
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
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
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
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
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
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
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
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
I'm talking about the "I've already said that the main trigger runs every 1 second. That is the event."
 

Dirac

22710180
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
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.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    Make sure you keep checking out my news..
    +2
  • Jesus4Lyf Jesus4Lyf:
    Man, I made this account 15 years ago? Wild. :)
  • Ghan Ghan:
    Seeing J4L is definitely a blast from the past.
  • Jesus4Lyf Jesus4Lyf:
    Oh hey Ghan! Long time. :)
    +1
  • jonas jonas:
    J4L! What has happened in your life
  • Jesus4Lyf Jesus4Lyf:
    Hmm, how to summarize... Moved to the USA and got married. Became a professional software engineer and solution lead. Learning Godot for game dev. :)
  • jonas jonas:
    So you are pursuing game dev as a hobby? What industry is your dayjob in?
  • jonas jonas:
    FAANG?
  • Jesus4Lyf Jesus4Lyf:
    Not quite FAANG, less pay for a less hours/stress. Yeah, game dev as a hobby.
  • jonas jonas:
    makes sense. Do we have a hobby game dev subforum to showcase some work?
  • Blackveiled Blackveiled:
    Happy Thursday
    +1
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    TGIF!
  • The Helper The Helper:
    hey tom_mai please do not archive anymore news
  • Ghan Ghan:
    AMD Ryzen 7000 next week :D
    +1
  • The Helper The Helper:
    noice!
  • tom_mai78101 tom_mai78101:
    "hey tom_mai please do not archive anymore news" ----> Got it. What should we do with the "News Archive" subforum?
  • The Helper The Helper:
    I think leave it for real old news that cannot be sorted the reason we had it in the first place was a server issue that we do not have anymore. I don't want to get rid of the archive just not put anything in it for now until we figure it out more
  • The Helper The Helper:
    The side chat has nothing on the discord. it is not possible but the biggest thing on my wish list right now is a sidechat channel on the disord that hooks up to this...
  • Ghan Ghan:
    I've been selected for the Diablo IV beta.
    +1
  • Ghan Ghan:
    Woo!
    +1
  • The Helper The Helper:
    that is so cool
  • V-SNES V-SNES:
    Eh just noticed the new discord section on the side. Looks great!
    +1
  • Blackveiled Blackveiled:
    :( feels bad I can't ever get selected for any beta I sign up for. It's annoying as heck.
    +1

    The Helper Discord

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top