Possible picking bug ?

Discussion and feedback on Construct 2

Post » Tue Nov 05, 2013 5:46 pm

Hello,

Just want to be sure, i have been able to reproduce a strange behavior with functions and picking.

I have two functions: One to create a sprite with ID (custom instance property) set to 3 and one to actually pick that sprite (based on ID = 3).

I am calling theses both functions in the event "On layout start". I though it would work.. i was expecting the picking function to pick the instance where the ID = 3 but the function that pick the sprite doesn't pick the sprite as if there was nothing to be picked but the sprite with the ID 3 got created in the first function.

But if i put two events "On layout start" and call the create function on one and the pick function on the other it work well!

I can't post a sample right now since i am not at home. But you should get the idea.. is this a normal behavior ? and why ?

Thanks!Rushino2013-11-05 17:48:51
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Tue Nov 05, 2013 6:35 pm

Hi, it's working by designed, as far as I understand.

Construct 2 always call the events from top to down, and creating the object in the same event where you're trying to pick it is not always possible because the runtime will try to create and pick the object at the same exactly time.

Instead, picking it right after, by using a new branch of events, is always possible and a good practice.TELLES08082013-11-05 18:36:13
Image
B
107
S
24
G
18
Posts: 1,361
Reputation: 22,770

Post » Tue Nov 05, 2013 6:52 pm

Yeah but creating and picking are not in the same event. Creating are in a function call and picking in another function call (so both in different events). But both function call are in the same event.. but it is the same thing as putting them in the same event ?Rushino2013-11-05 18:55:47
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Tue Nov 05, 2013 7:04 pm

[QUOTE=Rushino] Yeah but creating and picking are not in the same event. Creating are in a function call and picking in another function call (so both in different events). But both function call are in the same event.. but it is the same thing as putting them in the same event ?[/QUOTE]

Yes, they are in the same event, but not in the same action.

If they run in the same conditional level, they are in the same event, excluding sub-events, because when you run a sub-event, it will run top to down again and make the priority as a sequence.

For example.

-> Conditional: Every 5 seconds;
--> If object1 is NOT ON the screen:
---> Create object1 at X, Y;
---> Set object1 ID = 1;
--> Else
---> Destroy object1 with ID = 1;

it will run the code, create the object1, setup its ID = 1 and then destroy it in the same second;

Instead, you want keep it for 5 seconds and re-check it to destroy and create it again in another place, so:

-> Conditional: Every 5 seconds;
--> If object1 is ON the screen:
---> Destroy object1 with ID = 1;
--> Else
---> Create object1 at X, Y;
---> Set object1 ID = 1;


Edited:
I missed to say, sometimes, it's handful to use the action "wait=0,0" right after an action where you want make sure the order will be follow, inside the same conditional.

For example:

-> Every 5 sec;
--> Destroy object1 with Id = 1;
--> Wait 0,0;
--> Create object1 at X, Y;
--> Set ID = 1;TELLES08082013-11-05 19:15:39
Image
B
107
S
24
G
18
Posts: 1,361
Reputation: 22,770


Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk and 4 guests