How do I break?

Get help using Construct 2

Post » Wed Mar 11, 2015 2:42 pm

I have an event that switches a state from active true to active false, but also sets another object to active true which sets the first to active true so I just get a loop and nothing happens. I'm probably not explaining well but basically I have something like this:

OnEnterPressed(){
if (object1.active = true)
object1.active = false
object2.active = true
if(object2.active = true)
object1.active = true
object2.active = false
}

What I want to do as add a break so it only checks one if each time it is pressed.
B
10
S
3
G
1
Posts: 22
Reputation: 1,192

Post » Wed Mar 11, 2015 3:02 pm

I'm not quite sure what you want to do, but I have some idea. Can you fix it with an else statement?

I think the best solution is to use the System.TriggerOnceWhileTrue condition, which means that each object will only try and change the other when it is first activated. Then Maybe some kind of cooldown timer, depending on what you want to do.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Wed Mar 11, 2015 3:09 pm

so you want to a toggle switch.

I do this all the time, depending on what triggers it, it should be fine as is. If this code is in a "onclick" event, it's only going through it once, so you can just have 2 "ifs".

if it's in an area where it's getting triggered all the time, then you would just use an Else statement.

It all depends in what is triggering it.
B
66
S
19
G
8
Posts: 984
Reputation: 10,015

Post » Wed Mar 11, 2015 3:35 pm

bladedpenguin wrote:I'm not quite sure what you want to do, but I have some idea. Can you fix it with an else statement?

I think the best solution is to use the System.TriggerOnceWhileTrue condition, which means that each object will only try and change the other when it is first activated. Then Maybe some kind of cooldown timer, depending on what you want to do.


The trigger once seems like it'll help my enter press not be continuously evaluated, which is helpful, but it doesn't seem to help my main problem. I will attach a screenshot of my events for clarity.

As you can see I'm trying to switch the visibility of two sprites if one is active it's visible and two invisible if two is active one should be invisible and 2 should be visible. Right now if I delete the second if then it works but there's no way to get back. I'm trying to set up a toggle on enter pressed, if that makes any sense.
You do not have the required permissions to view the files attached to this post.
B
10
S
3
G
1
Posts: 22
Reputation: 1,192

Post » Wed Mar 11, 2015 3:38 pm

Try this:
OnEnterPressed(){
if (object1.active = true)
object1.active = false
object2.active = true
else
object1.active = true
object2.active = false
}

The system else event is used to create these toggle type of events. Since object2 is only set active with object1 is inactive, the else statement should work fine.
B
38
S
12
G
11
Posts: 329
Reputation: 7,708

Post » Wed Mar 11, 2015 3:46 pm

FragFather wrote:Try this:
OnEnterPressed(){
if (object1.active = true)
object1.active = false
object2.active = true
else
object1.active = true
object2.active = false
}

The system else event is used to create these toggle type of events. Since object2 is only set active with object1 is inactive, the else statement should work fine.


Thanks! Else worked.
B
10
S
3
G
1
Posts: 22
Reputation: 1,192


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests