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 The Helper:
    Happy Thursday!
    +1
  • The Helper The Helper:
    Happy My Birthday Eve! :)
    +2
  • V-SNES V-SNES:
    Happy Birthday @The Helper!!!
    +1
  • jonas jonas:
    wow, happy birthday
    +1
  • The Helper The Helper:
    thank you very much!
    +1
  • The Helper The Helper:
    I have been seeing a number of posts from current members being spam leading me to believe the bots might be brute forcing the register system guessing old users passwords
  • The Helper The Helper:
    The last 3 user bans have been this way
  • The Helper The Helper:
    no more new instances since the last message so it might not be a big thing
  • Ghan Ghan:
    We've seen that on RpNation as well. I think it's password reuse. Passwords are being compromised elsewhere and then tried on different sites.
    +1
  • The Helper The Helper:
    Happy Thursday hope everyone has an Amazing Day!
  • tom_mai78101 tom_mai78101:
    I'm having my Amazon Day.
  • tom_mai78101 tom_mai78101:
    Just resting from the cloud.
  • vypur85 vypur85:
    Hey all! Hope everyone is doing fine!
    +2
  • jonas jonas:
    Hi Vypur, how are you doing?
  • vypur85 vypur85:
    Hey hey all's good here. Last year I dropped a message saying I'll be moving to China for a new job. Here I am in China now for the padt year!
    +1
  • vypur85 vypur85:
    Past*
  • vypur85 vypur85:
    Missing this place much. Wish that WE is still a thing now, just like the past when everything was so active.
  • The Helper The Helper:
    Are you in Taiwan or Mainland China?
  • vypur85 vypur85:
    I'm in Mainland. At Wuhan. The place where all shit began...
  • vypur85 vypur85:
    Lol. After one whole year here, I learnt a few good and bad things about China.
  • vypur85 vypur85:
    Everything you do is pretty much observed. There are eyes everywhere... They can even read your Wechat texts if they want to...
  • vypur85 vypur85:
    But it's pretty much safe here. Walking alone in the middle of the night in weird dark alleys is completely safe...
  • The Helper The Helper:
    that is cool
  • The Helper The Helper:
    at least its safe

    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