How do I Perform action only once

Get help using Construct 2

Post » Wed Aug 10, 2016 9:33 pm

I want to write something like this:

Foreach Object1 {
Run Function CreateObject3()
}

Foreach ( imagepoint in Object1){
Create Object2 at imagepoint.x, imagepoint.y
}

Function CreateObject3(){
object3Count = Random(0,4)
for (x=0; x > object3Count; x++){
Create Object3 at imagepoint[x + 4]
}
}

I've tried to do this, but I keep getting an infinite loop.
B
9
S
4
G
1
Posts: 43
Reputation: 1,438

Post » Wed Aug 10, 2016 9:45 pm

@ephrisian

Have you tried System: Trigger Once ... ? Or System on Start of Layout ... ?
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Post » Wed Aug 10, 2016 9:59 pm

That's working out a bit better, but now I need to create object3 within object1. But because I'm calling it globally it's creating object3 in all instances of Object1

Here is what I have so far.
https://dl.dropboxusercontent.com/u/88974109/create.capx
B
9
S
4
G
1
Posts: 43
Reputation: 1,438

Post » Wed Aug 10, 2016 10:17 pm

@ephrisian

That is because you are using "For each Object1". Are you saying that you only want one or specific instances to call the function? I'm not sure what you are trying to achieve here, more info would help me help you :)
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Post » Wed Aug 10, 2016 10:21 pm

I'm trying to create 4 instances of Object2 inside of Object1 everytime it's spawned. Then I'd like to run a function that will generate a number between 1 and 4 and spawn that many of Object3 inside of Object1.

All of this happens when Object1 is being spawned.

I'm going to need to add more to that later because Object3 will have different "states" between 0 and 5.
B
9
S
4
G
1
Posts: 43
Reputation: 1,438

Post » Wed Aug 10, 2016 11:35 pm

@ephrisian

Ok, I looked at your capx and cleaned it up a bit. Is this what you are trying to do?

https://www.dropbox.com/s/cfgw8eata5r7t ... .capx?dl=0
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Post » Wed Aug 10, 2016 11:42 pm

@ephrisian

I created Array to store your imagepoints so that there are no overlapping Object3 (Objects sharing the same imagepoints)
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Post » Thu Aug 11, 2016 12:56 am

Yes, this example did match pretty much exactly with what I was looking to do.

Thank you!
B
9
S
4
G
1
Posts: 43
Reputation: 1,438


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 0 guests