Endless Trigger Loops

BlowingKush

I hit the blunt but the blunt hit me.
Reaction score
187
Anyone know the correct method to make an endless loop.

I need one for a game engine.
If you make a trigger call itself at the end of its actions, you get a stack over flow.
I also get a stack overflow if I have Trigger A call Trigger B when it is done and then Trigger B call trigger A when it is done...

any ideas?
 

Steel

Software Engineer
Reaction score
109
Endless loop...what? Need to give us more information. You could just make a trigger that executes ever second maybe?
 

BlowingKush

I hit the blunt but the blunt hit me.
Reaction score
187
if i make it event driven, it will not process near as fast as it would if it looped
 

Nei

New Member
Reaction score
0
Perhaps have an if at the end of your actions that gives a random number, so 90% of the time it calls itself but eventually it'll end, preventing that stack overflow?
Then call it again the next second.
 

tain

New Member
Reaction score
0
"While(LoopRunning==true) Do Actions"

LoopRunning can be global var type Boolean.
 

BlowingKush

I hit the blunt but the blunt hit me.
Reaction score
187
"While(LoopRunning==true) Do Actions"

LoopRunning can be global var type Boolean.


Tain, I took your racing game loop and removed all the actions except the wait 0.0 sec and a counter x=x+1.
The counter will count to 33 after 1 Real time second.

That means the fastest response you can get in Galaxy is 33 action loops per second.
But using a little trick you can get as many executions you want per second.

Remove the wait statement and the loop errors out.

So here it is. A fast and easy way to get a loop faster then the 16 limit that Timer events have.

The smoothtimer, although it may 'fires' 32 times per sec, will never process more then that do to the limitation of trigger processing.
 

Attachments

  • 66TimePerSec.zip
    64.7 KB · Views: 255

Steel

Software Engineer
Reaction score
109
Tain, you are incorrect. As J4L has already stated waits are inaccurate. The actual wait of 0.0 is 1/32 of a second. The WC3 engine could handle 8124 (?) operations per second before it required a wait due to stack overflow. So it doesn't have anything to do with rendering. I'm pretty sure the game could handle a few thousand (hundred thousand) operations before it needed to do anything.


For the OP:
repeatforever.png
 

BlowingKush

I hit the blunt but the blunt hit me.
Reaction score
187
So what exactly does Galaxy need that 1/32 sec (wait 0.0) for? You not adding to the stack unless your calling a function recursivley, so how do you risk a stack overflow?
 

Cookiemaster

New Member
Reaction score
36
So what exactly does Galaxy need that 1/32 sec (wait 0.0) for? You not adding to the stack unless your calling a function recursivley, so how do you risk a stack overflow?



Try making a huge array in GUI.

Like Integer[100][100][100].

SC2editor will throw a "script too long" error, due to it wanting to assign every single field, generating a script that sets 1,000,000 variables at once.
 

tain

New Member
Reaction score
0
Try making a huge array in GUI.

Like Integer[100][100][100].

SC2editor will throw a "script too long" error, due to it wanting to assign every single field, generating a script that sets 1,000,000 variables at once.

but this has nothing to do with game loop.
please i am waiting over day to get to my PC home so i can test the hell out of it :D
ill post test results asap :D

btw. with the loop you should be able to create Int[100][100][100]
ill test this also
 

tain

New Member
Reaction score
0
Tain, you are incorrect. As J4L has already stated waits are inaccurate. The actual wait of 0.0 is 1/32 of a second. The WC3 engine could handle 8124 (?) operations per second before it required a wait due to stack overflow. So it doesn't have anything to do with rendering. I'm pretty sure the game could handle a few thousand (hundred thousand) operations before it needed to do anything.

sorry, but waits are 100% accurate in single player (probably in bnet also).
and you can iterate each 1/32 second as long as you have enough CPU.

i tested this code:

Trigger:
  • Actions
    • RepeatForever()
      • actions
        • Repeat(10000)
          • actions
            • SetVariable(counter, (ArithmeticInt(counter, +, 1)))
        • Wait(0.0, c_timeGame)


and i output the counter after 5 seconds of the game and i get exactly 1610000 each time .
so with the game loop code, you can create as many TICKS_PER_SECOND as you wish :D but only render 32 game states per second.
be aware that we are talking about Game Time, not real time.


////////////////////////////

Try making a huge array in GUI.

Like Integer[100][100][100].

SC2editor will throw a "script too long" error, due to it wanting to assign every single field, generating a script that sets 1,000,000 variables at once.

also false. it will loop like this:

Code:
//--------------------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------------------
int[101][101][101] gv_untitledVariable001;
int gv_counter;

void InitGlobals () {
    int init_i;
    int init_j;
    int init_k;

    init_i = 0;
    while (init_i <= 100) {
        init_j = 0;
        while (init_j <= 100) {
            init_k = 0;
            while (init_k <= 100) {
                gv_untitledVariable001[init_i][init_j][init_k] = 0;
                init_k = init_k + 1;
            }
            init_j = init_j + 1;
        }
        init_i = init_i + 1;
    }
    gv_counter = 0;
}

but in this case, it wont be able to allocate the large array because it doesn't allow that much memory for global vars.
 

PrisonLove

Hard Realist
Reaction score
78
I didn't read the whole thread (probably a mistake), but as for endless loops. I believe GE has the [ljass]while() loop[/ljass] does it not?

In that case can't you just do this? [ljass]while (true) { }[/ljass]

I don't actually have the beta yet (I have to wait for the mac client, grrr), I'm just going off of what I've heard and what I know from general porgramming.
 

BlowingKush

I hit the blunt but the blunt hit me.
Reaction score
187
Running multiple instances of your handler will run twice as fast
just call your trigger twice
although I have yet to make 2 instances run evenly 'desynced'
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top