A conceptual question...

This forum is currently in read-only mode.
  • Hello everyone!

    This is my first real question here in Construct forum, and while it's not a "How do I" question, I'm not sure if this is a good one.

    Right now, I'm really enjoying Construct! It's so easy to understand! I'm already starting some personal projects on it, and so far everything ran smoothly.

    However, I'm puzzled by how Construct checks its events. I'm no programming expert - only dealt with Actionscript 2.0 and a bit of LUA (for scripting and interface implementing). And I did something on Construct I didn't think would be correct, but in fact it worked perfectly! I'm sorry if this question sounds stupid, but I'm still learning the ropes here

    Here's my doubt:

    <img src="http://img172.imageshack.us/img172/383/particle.jpg">

    I've decided to test the particles on Construct, so I've created a BulletParticle at the X,Y of the GoodBullet (event 5). To make the particle follow the bullet, I've decided to simply attach the X,Y of the particle to the bullet, on the Always event (1).

    This way, I expected to see probably just the first bullet with a trail, as it was placed offscreen... But I wasn't expecting for all the bullets to already come out with a particle attached!!! .

    I noticed that once the bullets are out of the scenario, the particles go to 0,0 (because the bullet is dead, I get it). But I can't understand how Construct can check what bullet each particle should follow, as it's on a "Always" event, and it's not related to the whole "creating bullet" event.

    If I were to create something like this on Flash, for example, I'd have to create instances for each of the bullet and particle, so that my particles knew which bullet they should follow. I know Construct is meant to be easy, but this is just too much!

    Can anyone explain this to me?

    Thanks in advance!

    edit: Here's the CAP file: http://www.gammabeam.net/streetdefender_01.cap

  • This is called object pairing. I think you'll find it useful!

    When you run an action, it repeats the action once for each instance. For example:

    + Every 1000 ms

    -> Sprite: spawn bullet

    This will repeat the 'spawn' action once for each Sprite instance that exists, so if you have 5 sprites, 5 bullets spawn. (If the conditions involved 'Sprite' at all, then the action only applies to those which met the event, but when they aren't in the event, the action applies to all of them)

    Similarly, when you say 'Set X', it repeats it for each instance. However, the value of 'GoodBullet.X' is not constant for the repetitions of the 'Set X' action. As it switches between instances of 'BulletParticle' running 'Set X', it also switches between instances of 'GoodBullet', kind of rotating round all the objects pairing them up. This means objects naturally just pair up together, which, more often than not, is useful.

    By the way, you might benefit from putting 'GoodBullet' and 'BulletParticle' in a container.

    Hope that helps

  • A quick one before I head off to bed..

    You can assign the particle to the bullet object through containers (there's a tutorial on the forum somewhere). That way, when a bullet is spawned or destroyed, the particle is too.

    In events you'd have something like -

    ForEach BULLET

    + PARTICLE.x = BULLET.x

    + PARTICLE.y = BULLET.y

    and so on..

    means it's an EVENT

    and + means it's an ACTION

    that was a quick sample and I'm sure someone will give a better one soon enough

    edit> seems Ashley beat me to it

  • Yeah I was wondering if they were both being destroyed because they were outside layout.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the explanation guys!

    I think I get it... I'll try to search a bit further on this "pairing" feature, it sure seems useful!

    I was starting to check on the containers, I�ll study that too.

    And now, just a question that came from your explanations... If I wanted to use a same sprite object, but I didn't want the second one to pair with the event (ex. Left and Right flippers of a pinball machine): How can I discriminate one sprite from the other? Do I have to duplicate the object and rename the copied one?

    Also, if this is the kind of thing that's somewhere in the tutorials, please be rude and tell me to go look myself! I don't wanna be wasting nobodies' time

  • Just use some kind of condition to pick one. You could have a private value set to "left" and "right" for each one, then have:

    + Shift pressed

    + Flipper value 'type' = "left"

    : Do something with flipper

    That'll only affect the one.

  • Ah, so that's what the private variables are about!

    Thanks! I expect to upload a version of the game soon!

  • Ah, so that's what the private variables are about!

    They're about a whole lot more than just that. You can store whatever value you want, for whatever purpose you want.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)