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
413
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
413
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
413
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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