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

Get help using Construct 2

Post » Thu Jan 19, 2017 10:02 pm

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 :
Image
Last edited by pokka on Fri Jan 20, 2017 1:38 am, edited 5 times in total.
Image
B
21
S
7
G
3
Posts: 32
Reputation: 2,977

Post » Thu Jan 19, 2017 11:07 pm

The capx depends on a behaviour that comes with the price of €8.19.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jan 19, 2017 11:17 pm

oh damn, I'm really sorry for that, but I'm sure i removed every item/value related to it, how is that possible ?
Last edited by pokka on Thu Jan 19, 2017 11:29 pm, edited 2 times in total.
Image
B
21
S
7
G
3
Posts: 32
Reputation: 2,977

Post » Thu Jan 19, 2017 11:22 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jan 19, 2017 11:28 pm

Shouldn't be dependant anymore, can you confirm ?
[Edit] Working link : https://mega.nz/#!ZBwB3ahY!4fp_1IcK6dDU ... DA-8QEdRQ8
Image
B
21
S
7
G
3
Posts: 32
Reputation: 2,977

Post » Fri Jan 20, 2017 2:16 am

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.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Fri Jan 20, 2017 10:29 am

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jan 20, 2017 11:13 am

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:

Image

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
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Jan 21, 2017 11:36 am

@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.
Image
B
21
S
7
G
3
Posts: 32
Reputation: 2,977

Post » Sun Feb 12, 2017 3:48 pm

99Instances2Go wrote: 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 :(
Image

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...
B
6
S
1
Posts: 73
Reputation: 569

Next

Return to How do I....?

Who is online

Users browsing this forum: AndreasR, David181, karthikavnair and 8 guests