Objects immediately disappearing.

Get help using Construct 2

Post » Mon Jun 30, 2014 5:19 pm

I've been having the usual problem of not being able to use objects which have just been created which are on the same 'level' as the next groups of code. As such, I've had to move the function to create my objects to a higher level, so that the next group of code is in the level lower. But now the strangest thing is happening.....

I create my objects in a function (which is at an even higher level and I can confirm that the objects are created) but in the very next line of code, when I do an object.count, it's back to zero.

I've always had this problem with C2 and the solution is usually to check that the objects are created on a higher level, but it seems to have changed.

So it's like this.

-------> Call Function to create objects
Object count is zero.

--> Function to create objects (top level).
Object count is 10 when leaving function.
B
26
S
6
G
4
Posts: 456
Reputation: 5,853

Post » Mon Jun 30, 2014 6:32 pm

Can you upload the capx so we can check what you're doing wrong?
B
6
S
1
Posts: 73
Reputation: 571

Post » Mon Jun 30, 2014 6:35 pm

Unfortunately not because it's huge and won't work without the access to my database. I've had no choice but to make the objects permanent from the start of the game instead of creating them just for a certain screen (and then deleting them later). It's working now, but I'm not sure what was causing that problem before.
B
26
S
6
G
4
Posts: 456
Reputation: 5,853

Post » Mon Jun 30, 2014 6:46 pm

Sprite.Count will return 0 if there are no existing Sprites. You can't call an expression (.Count) on a Sprite object if there aren't any Sprite objects. It would be like using Sprite.X or Sprite.Width when no Sprites exist. It would just return 0.

So after the function call where the objects don't exist yet, then there is no object to call object.count on. But if you had at least 1 object already on the layout then it would work.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Mon Jun 30, 2014 7:48 pm

But surely if the function creates the sprites, then immediately after returning from the function, sprite.count should show 10 (I made 10). Or is your point that the objects don't actually 'exist' at that point? If so, when do they begin to exist?

I should say that I'm happy with having these as permanent objects anyway really, I can just keep them offscreen when they're not needed. But it'd still be interesting to know what happened.
B
26
S
6
G
4
Posts: 456
Reputation: 5,853

Post » Mon Jun 30, 2014 10:05 pm

The sprites aren't properly created until the event that calls the function finishes. The sprite count IS updated immediately... but you can't access sprite.count if no sprite exists.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Mon Jun 30, 2014 10:21 pm

So even in a sub-event they won't be accessible? I need to wait till the entire event finishes? This keeps tripping me up with C2.
B
26
S
6
G
4
Posts: 456
Reputation: 5,853

Post » Thu Jul 10, 2014 5:26 am

I had this same problem when using the save \ load features. Objects would exist but would disappear after a load and just act strange. Can you attribute the disappearances with occurring after a "load" Switching to Webstorage fixed it for me.
I didn't do a bug report either due to project size.

Good luck.
Image
B
36
S
14
G
11
Posts: 142
Reputation: 8,465

Post » Thu Jul 10, 2014 11:24 am

I'm fairly sure in my case it was because I was trying to use them in the same event after creating them from a function. Although they still wouldn't work in sub-events. But when I set up the same structure in a few project, it did work, so something must've been wrong with my code somewhere.
B
26
S
6
G
4
Posts: 456
Reputation: 5,853


Return to How do I....?

Who is online

Users browsing this forum: DarthPapalo666 and 33 guests