Duplicate spawning/creation problems

For questions about using Classic.

Post » Fri Dec 18, 2009 1:08 am

Crash=bug, so make sure that's reported.

As for the spawning problem, this is an extremely interesting .cap. I have investigated it and at first there seems to be a problem with the timer behavior. If you replace the timer behavior with a simple "Every 500 ms" condition, the interesting stuff starts happening.

It looks like the initial object moving to the right incorrectly keeps resetting its fade behavior, while the objects it's spawning also don't get a fade in. But it is actually working correctly!

Let's go back to what Spawn Object does in terms of picking. Say you have an object called A, and in an event which picks A1, it spawns A2. Should you get A1 and A2 picked, or just A2? The code is supposed to pick A2 only since it's the only new created object (the system create object action works this way). This way you can control A1 by actions before the spawn action, and control A2 with actions after the spawn action.

In this particular case though, you end up with just A1 picked - spawning an object does not pick it and the actions affect the original object! This means the 'Set angle to .angle+90' and 'set type to 2' apply to the object moving horizontally. So it ends up redirecting itself downwards, and spawning another object to continue its current path. It's kind of backwards and crazy, but it's actually necessary. If you spawn an object of the same type as the object spawning, the new object cannot be picked because of limitations in the engine. The reason is very complicated, but the code behind running a general action is:

For each currently picked instance 'Obj':
-> Run action for instance 'Obj'

So for example 'Set X to 0' runs the 'set X' action for every picked instance. However, in the 'spawn object' action, it would modify the list of currently picked instances, which it is currently processing in a for-each. This can cause a crash, so the fix was to prevent spawning an object of the same type from picking the spawned object. This results in the counterintuitive behavior in your example .cap.

The fix? I don't know what the best thing to do is; this picking behavior probably can't be changed in the 0.x engine because it's so integral to the running of actions. I think the best thing to do is to always spawn a different object type (even if it looks the same). So you could have RedBulletA spawning RedBulletB which in turn spawns RedBulletA again. You can then use families to save repeating events. Hopefully that will do you for now.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri Dec 18, 2009 4:26 am

so.... system->create object picks the newly created object, but spawn doesn't?
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Fri Dec 18, 2009 10:06 am

Yes, when you're spawning an object of the same type. If you spawn an object of a different type, it can be picked.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri Dec 18, 2009 10:51 am

Well, create and families seem to work quite fine for my intended purposes... though for some reason I can't get timers to work with it. The cap straight out refuses to compile. In any case, take a look at this:

viewtopic.php?f=16&t=5274&p=41948#p41948

When you run it, you can see that the first bullet creates bullets to both left and right, but then only the left side creates further two bullets. The right side should also create two more bullets and destroy afterwards, but right now it only destroys.

Any ideas on how to solve this?
B
16
S
8
G
4
Posts: 136
Reputation: 3,144

Post » Fri Dec 18, 2009 5:59 pm

Can't catch a break on this picking thing, huh? :P

What's happening is that in the second wave you have not one but two objects that are spawning things, and you're not picking them by anything more than "timer > 500, type = 2." Since both objects meet the criteria for the condition Construct doesn't know which one you mean so it selects the first created instance, which is the one that was created first in wave 1. This is the one that spawned to the left (Angle+90).

You need to tell Construct that you intend for every instance that meets the criteria to follow these instructions, so you need to add a For Each loop to wave 2.

http://dl.dropbox.com/u/529356/spawnforeach.cap

By the way, you should probably use absolute angles when spawning the second wave, because using relative angles makes each side shoot in different directions.

Oh, and if you intend for there to ever be more than one first wave bullet on the screen you should probably add a For Each to that sequence as well.

Also, I saved that in 0.99.62 so you might need to upgrade.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest