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.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top