Triggers not triggering / reseting correctly

Get help using Construct 2

Post » Mon Dec 19, 2016 5:31 pm

Ok, I have a family of objects that I'm trying to have activate/deactivate triggers. It works for individual object but if I try to have multiple objects (with different ID's set by instance variables) it starts acting up. What am I doing wrong here:

FAM_OBJECTS is overlapping TRIGGERSPRITE ->
For each TRIGGERSPRITE
System Pick OBJECT where OBJECT.ID = TRIGGERSPRITE.ID
Trigger once

-> OBJECT set boolean true

Else
FAM_OBJECTS is not overlapping TRIGGERSPRITE
Pick all TRIGGERSPRITE
OBJECT ID = TRIGGERSPRITE.ID
For each OBJECT
Trigger once

-> OBJECT set boolean false



It seems to trigger/deactivate correctly for one object but with multiple objects overlapping triggers with different ID's problems arise. I can't figure out how to fix this so any help is much appreciated!:)
B
31
S
9
G
4
Posts: 131
Reputation: 4,321

Post » Tue Dec 20, 2016 12:53 am

The picking is a bit off there. The logic you need will be :
For each objects
Objects is overlapping TriggerSprite
Objects.ID = TriggerSprite.ID

Set bool true
Else
Set bool false

Obviously the family and trigger sprite are interchangeable depending on if you really have to check against the trigger sprite's variable and not the family.
B
46
S
15
G
73
Posts: 2,026
Reputation: 43,459

Post » Tue Dec 20, 2016 8:58 pm

@plinkie Thank you very much for your help!

I tried the solution proposed but unfortunately I still haven't been able to make it work. Here's an example capx (sorry about the couple of disabled extra conditions as I was trying different things to solve this!):

https://dl.dropboxusercontent.com/u/163 ... oblem.capx

Both triggers activate correctly but don't deactivate. I suspect I'm using "trigger once" wrong here, but if I remove it then no visible changes happen at all (infinite loop?).

I've been trying to get this to work correctly for several hours now and it's getting tiresome so if anyone has time to take a look at the new capx and have ideas on how to fix it I'd be very grateful :)
B
31
S
9
G
4
Posts: 131
Reputation: 4,321

Post » Tue Dec 20, 2016 10:25 pm

it's the Else you're using wrong, it should all be in one event. Have the ForEach at the top of the event, then in 2 subevents (press S) have the first section and the else section.

https://www.dropbox.com/s/i10yoc3d3u0mp ... .capx?dl=0
B
46
S
15
G
73
Posts: 2,026
Reputation: 43,459

Post » Tue Dec 20, 2016 11:01 pm

Thank you so much again @plinkie!

This is a definite improvement, but I noticed one more problem with the other object, as demonstrated in this capx:

https://dl.dropboxusercontent.com/u/163 ... ed_V2.capx

I gave both objects platform behavior movement for demonstration/testing purposes. If the blue box overlaps with the trigger without the pink overlapping a trigger, nothing happens. However if pink alone overlaps trigger it activates, and if both overlap both triggers activate.
B
31
S
9
G
4
Posts: 131
Reputation: 4,321

Post » Tue Dec 20, 2016 11:25 pm

B
33
S
18
G
28
Posts: 2,477
Reputation: 20,918

Post » Tue Dec 20, 2016 11:33 pm

Oh I see what you want it to do now, I was using family instance variables. Yeah you don't need a for each, just if family is overlapping switch and switch ID matches block ID then set to true.
B
46
S
15
G
73
Posts: 2,026
Reputation: 43,459

Post » Wed Dec 21, 2016 12:00 am

@99Instances2Go & @plinkie

Awesome, you guys are the best! :)
This was very helpful and now it seems to work exactly as should, I can finally move back onto tackling other mechanics in my game. Thanks again!
B
31
S
9
G
4
Posts: 131
Reputation: 4,321

Post » Wed Dec 21, 2016 8:39 am

See, the thing is. A condition has a logic part (if true it runs its actions) and a picking part (it makes a list of selected objects).

If you want to set a Boolean based on the logic (true/false) you best use an 'else'. Else means 'if the previous condition did not run (hence it is false), run this condition.

If you want to set a Boolean to a list of picked objects (true), and set the opposite the unpicked objects (false), then the the second condition will be the first inverse. But, that second condition cant be a sub of the first because those objects are not picked by the first one.

Now, those two 'rules' combined. Often it means (for the logic based else) that the top conditions are the picking conditions. Then a sub with that logic condition, then attached to that sub the logic else. Or in general:

Pick object A
Pick object B
______Logic condition
_____________________actions
______Else
_____________________actions

Example

You want set a boolean if a object is onscreen, if none of that object is onscreen you want to set the boolean to false.

(object) Is onscreen
_____________________set boolean true
else
_____________________set boolan false

Or. You want to set a boolean of all instances of an object to true when they are on screen, and to those that are offscreen you want to set the boolean to false.


(object) Is onscreen
_____________________(object) set boolean true

(object) Is (NOT) onscreen <----- no sub and INVERSED
_____________________(object) set boolean false
B
33
S
18
G
28
Posts: 2,477
Reputation: 20,918

Post » Wed Dec 21, 2016 10:50 pm

@99Instances2Go Thank you for the explanation, I really appreciate it! I think I have a better understanding on how picking and booleans work now!
B
31
S
9
G
4
Posts: 131
Reputation: 4,321


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, SputnikCZ, Yahoo [Bot] and 3 guests