[Capx]How to execute events at the last cycle/end of a loop?

  • Hello, as you can see in my capx at condition For "ForExplodeMultipleCircles" from 0 to VarParam_0 I nested another condition which should reset my variables at the last cycle (or if possible once the loop finished), but looks like it doesn't work, do you have any tips or solution to this annoying problem ? The final result would be of bullets spawning every time from the same point since variables are being resetted, right now for example if you press num4 the first time you get 0+180 degree, the second 180+180, which should be 0+180 and 0+180.

    Link to the capx : https://mega.nz/#!ZBwB3ahY!4fp_1IcK6dDUf9EYJg4Xa3fEb6AoPh9s8DA-8QEdRQ8

    [Edit] Capx finally not dependant from external behaviour

    Screenshot of the code :

  • The capx depends on a behaviour that comes with the price of €8.19.

  • oh damn, I'm really sorry for that, but I'm sure i removed every item/value related to it, how is that possible ?

  • Need to de-assign (delete) the behaviour in the objects. But that is gonna mess up the project ? All ACE's related to it will disappear.

  • Shouldn't be dependant anymore, can you confirm ?

    [Edit] Working link : https://mega.nz/#!ZBwB3ahY!4fp_1IcK6dDU ... DA-8QEdRQ8

  • You can't use Wait loopindex... because loopindex won't have the correct value after the wait, since what happens is all of the loops are called at the same time, but the events under them aren't called until later, so loopindex is no longer valid. You are better off using Timers for this kind of thing. They make life a lot easier, as Wait often doesn't work the way people expect.

    If you disable that first Wait, you'll see things improve. You also have the loopindex=VarParam_1 check outside of the loop, which is bad form, and won't work anyway, as the numbers don't make sense. Look at the first case: you loop to 8, but check if the index is = 9, which it never will be. It's a cumbersome method anyway, to reset the variables.

    It's not entirely clear how you want this to work, so I can't offer a concrete example of how to do this better.

  • As blackhornet mentioned, you have problems with the 'wait'. Personaly i hate the use of 'wait'.

    But that is not all.

    Using globals for variables that have to be reset is also cumbersome. Use locals, and trust that they will be reset.

    Not that i exactly know when you want to reset them. And that is because you use 'loopindex' in a nested loop. The repeat also sets the system expression 'loopindex'. So, which 'loopindex' do you want to use ? That one from the 'for' or that one from the 'repeat'. You have to name your loops, so you can use 'loopindex("name").

    For the same reason i have no idea (and so does the system) which loopindex is used in setting the bullet angle.

    Back to the 'wait'.

    The main problem with the 'wait' is this: You give a variable a value. Then you postpone the action that is gonna use it. But before it can be used, you give it a new value. And the previous value is lost.

    You actual have to store the states of that variable until they are used. Then they can be lost.

    Say, i have 4 kinds of whine. I give you a bucket. Now i fill your bucket whit whine, and tell you to bring it to a client in 5 minutes. Then i empty your bucket. Pour in another whine, and tell you to bring it to another client in 5 minutes. How you gonna manage that? You can not serve the first client no more.

    You will ask me for more buckets.

    More buckets stand for a variable that can hold many values. And that is in fact an array. Or: An array is 1 variable that can hold more then 1 value on places that can be addressed with an index. (bucket 1,bucket 2, bucket 3 ......)

    Again. Not that i know what you precisly want. But here is an example that should teach you how to make exactly what you want.

    https://drive.google.com/open?id=0B1SSu ... XByNTY2UXc

  • Functions only "exist" during the single tick/frame in which they are called and loops are also executed and completed during the same tick/frame they are started in (easiest way to kill framerate is to run lots of big loops). Any every X seconds actions or wait X seconds actions will generally not work within a function (there are some exceptions with wait). If you want to do actions across multiple frames or seconds of real time, you need to use different tools.

    Also if you want variables to reset after a function is done, just set them to be local variables by moving them under the event.

    I understand you want to do something like the below, please correct me if I am wrong:

    What you should be doing is either using timer behaviour to change the firing angle and spawn a bullet every X seconds. Or using an instance variable as a counter that gets lowered by x*dt.

    Here is an example:

    https://www.dropbox.com/s/xva53ndw82f5x ... .capx?dl=1

  • Pulstar 99Instances2Go blackhornet Thanks to you all for the explanations, I wasn't aware of how wait react inside a loop. Also thanks for the capx, tobyr worked on it too, so once i learnt everything from all yours capx, i'll update the download with a fixed one, so this thread may be be usefull to the entire community.

  • Personaly i hate the use of 'wait'.

    I hate it too!!! Every time i try to do something with Construct and i have to delay something, i have shivers. Becausei know that i'll need to use Wait function and that i'll never get it to work as intended. Sice i was young, i never had problem with wait command, but this Wait is impossible to handle for me....

    I'm now making an Adventure Game and i need to make the classic dialog with more then one sentence, with a pause between them

    I've lost the entire day and finally i discovered the issue in Loopindex.

    I really can't understand why the first loopindex works (wait loopindex*1 seconds) and the other one no

    This is inside a function: It has 2 parameters, needed to find the sentence in the XML file. I have divided with | the words (like:

    <Description>Hello|World</Description> and then split with tokenat

    The Loopindex("token") inside the Tokenat part will always give 0...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Use a Timer instead. You have full control over how it works.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)