Is object picking 100% reliable?

Get help using Construct 2

Post » Tue Feb 07, 2017 3:26 pm

I have to ask. It's probably some kind of bug on my end but I can't find it and it's driving me a bit nuts :P

I have a group of object instances (Character) I loop through every game tick. Like this:
Image

Every loop calls a few functions to handle the current Character's movement, collisions, and rendering:
Image

I'm passing object UID's to these functions, which is probably bad practice. But they're global objects created on startup and their UID's never change. So it should be okay.

The problem happens in Collider_Chr(). This function aligns a couple of collision boxes on each side of the Character object and checks if they're overlapping with anything. If one of them does, an instance boolean gets set to true. If there's no overlap, the boolean is false.

Image

This function is structured the same way basically as everything else in the game: I pass an UID to the function, then pick the Character instance from that passed parameter. And it works fine. Except in this case. This event/function doesn't want to pick the right Character instance for some reason, so all the collider objects get set to the position of the first Character in the main loop.

I can't figure it out. This 'pick instance by passed function parameter' approach works fine everywhere else, at least as far as I can tell. Anyone able to see what I'm doing wrong here?
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Tue Feb 07, 2017 3:52 pm

Try to separate overlapping "or" conditions into separate events. Usually overlapping test won't work correctly with "or" condition.
ImageImage
B
102
S
45
G
22
Posts: 772
Reputation: 21,493

Post » Tue Feb 07, 2017 4:09 pm

I split them up and it worked! Thanks so much :)

That's a pretty mean gotcha. Is the 'or' operator a bit flaky in general maybe?
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Tue Feb 07, 2017 4:22 pm

If you separate them, you might have a problem with the 'else'.

I suppose that 'platform' is a tilemap and 'breakable' a sprite. So you cant bring them in 1 family.
So, make 'breakable' a tilemap, if possible. Now just check overlap with 1 family. I what i prefer.

You can separate them like ...

is overlapping platform
____set boolean
else
is overlapping breakable
____set boolean
else
____unset boolean

i think that should work
B
33
S
18
G
27
Posts: 2,451
Reputation: 20,366

Post » Tue Feb 07, 2017 4:24 pm

I don't know what exactly underneath, but it work just like that for overlapping test. But you can combine overlapping test condition with "and" condition (normal without "or") just fine. "Or" condition is reliable outside from using it for overlapping test.
ImageImage
B
102
S
45
G
22
Posts: 772
Reputation: 21,493

Post » Tue Feb 07, 2017 4:30 pm

I don't think you need the for each, and you definitely don't need the every tick.
Image ImageImage
B
168
S
50
G
163
Posts: 8,224
Reputation: 105,067

Post » Tue Feb 07, 2017 4:33 pm

ErekT wrote:I'm passing object UID's to these functions, which is probably bad practice. But they're global objects created on startup and their UID's never change. So it should be okay.

Here are some tips you might find helpful when trying to pin point problems.

What you can do is to create a log and use that to track what is going on more closely in the code. Just make a List and call it List_Log or whatever you prefer. Change it from dropdown list to a listbox in the properties menu, then you can use the additem varies places where you think things might go wrong.

Image

Also there is nothing wrong in passing UID to a function, in fact its very good to do so, because they are unique. Not that there is anything wrong in your picking. But what you can do that might simplify your picking, is to do what I have done above. The red area in my example does exactly the same as in yours. However you don't have to use local variables etc. anyway just a tip.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Tue Feb 07, 2017 4:40 pm

99Instances2Go wrote:If you separate them, you might have a problem with the 'else'.

I suppose that 'platform' is a tilemap and 'breakable' a sprite. So you cant bring them in 1 family.
So, make 'breakable' a tilemap, if possible. Now just check overlap with 1 family. I what i prefer.

You can separate them like ...

is overlapping platform
____set boolean
else
is overlapping breakable
____set boolean
else
____unset boolean

i think that should work

Yeah no prob, I structured it like this:
Code: Select all
Pick Collider -
                                 | Set C_CannotBePushedRight to False     (defaults to this)

   Is overlapping     | Set C_CannotBePushedRight to True


I did discover that another problem event got cleared up by going from this:

Code: Select all
Is ConditionA            | Do stuff
       - or -
Is ConditionB 
Else                           | Do something else


... to this:

Code: Select all
Is ConditionA           | Do stuff
Is ConditionB          | Do stuff
Not ConditionA      | Do something else
         - and -
Not ConditionB


Not trusting 'or' from now on :P

@nimos:
That's a nice trick, thanks :)

@newt
Is there a more efficient way to iterate through them? I use a boolean to minimize the looping already (Activated). Every tick, yeh I agree. Lots of game logic that needs updating if I change it but maybe I should anyway.
Last edited by ErekT on Tue Feb 07, 2017 4:46 pm, edited 1 time in total.
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Tue Feb 07, 2017 4:46 pm

Perhaps you should use the inverse logic, although it could be a bit slower.

Not overlapping object A and Not overlapping object B -> Set to False
Else -> Set to True
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Tue Feb 07, 2017 4:50 pm

Other than getting rid of the functions is activated should do fine.
Image ImageImage
B
168
S
50
G
163
Posts: 8,224
Reputation: 105,067

Next

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], newt and 10 guests