how to give commands to a specific instance (solved)

This forum is currently in read-only mode.
From the Asset Store
In this game you will command the character by voice command.
  • I need to give some commands to a specific instance of a sprite. Let's say that I have more than 1 instance of that sprite, and I want to give an order to the sprite that has a certain private variable to move.

    How do I do that?

    Thank you.

  • I have a similar question:

    I tried to make a function where you can push boxes around in grid movement. I didn't get very far before I noticed that the events addresses ALL of the boxes instead of the one I'm actually colliding with. Which means that when I'm pushing a box one direction, it's actually pushing all of the boxes in the same way.

    In MMF2(which I have some experience with) it automatically targets the right one and the others are left alone.

    What can be done to fix this? Or, what would be a more affective way to achieve the push-function?

    Link to .Cap-file:

    http://falconshield.com/spel/dungeon%20construct.cap

  • Cristi, you should insert a "Compare Private Variable" condition into your event. If PV (Private Variable = X (X being the value you want it to pick for).

    Falcon, I haven't looked at your .cap but it sounds like you should try flipping the collision condition. Instead of Player collision with Box, put Box collision with Player.

  • On creation of a sprite give its private variable an unique ID, I personally use the spawn object UID for that.

    Then do this:

    For each object <your sprite>

    __If sprite private variable is equal <UID you need> -> Do stuff to sprite

    [generally what Mr Wolf wrote]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On creation of a sprite give its private variable an unique ID, I personally use the spawn object UID for that.

    Then do this:

    For each object <your sprite>

    __If sprite private variable is equal <UID you need> -> Do stuff to sprite

    [generally what Mr Wolf wrote]

    I don't really think they'd need to use UID. How would they know which UID they'd need anyway? I don't see how this helps picking... Also, if they are just setting the object's Private Variable to the object's UID, then that is redundant. The object's UID already stores the UID...

    Now if they were pairing two objects created in the same event, they could set each one's PV to be the other one's UID (or just do that for one of them depending on what you're doing) and that would work for certain things, but in this case, no.

  • I have tried to use a for each object >compare variable, but... is quite slow and a better approach will be for each object created to have a unique id, like a .com hwnd so that once you get the object id you can pass it to a variable and use it when you like and how you like.

    Also, a good feature is to use something like "IDvar=system.createobj.getID" to get the id and "obj(IDvar).do_stuff" for reference and commands.

    I guess for now, for each and compare must do the trick..... and it does so far.

    I will post this suggestion in the feature request section.

    thank you all.

    If any of you have any more suggestions for this issue please post them here.

  • Wolf: I didn't wrote they need, I wrote I did it that way. It is handy for me so the object remembers its parent. I merely suggested it as a good 'coding' practice.

    In the even part the UID stands for any UID of the sprites object. They have to be uniqe so the picking is done right. Unique in the sens that it is right for only the ones you want to pick. You could pick more than one with such 'for each' loop.

    I just thought I would elaborate on your hint as I reckoned it was to short and 3 days ago I wouldn't understand it myself.

  • Why are you guys overcomplicating things?

    Let's say that I have more than 1 instance of that sprite, and I want to give an order to the sprite that has a certain private variable to move.

    Loops aren't needed for this. Simply compare the private variable of the sprite.

    Here's a lazy example: http://dl.dropbox.com/u/2306601/movepv_001.cap

    Sprites with a PV Move of 1 will move to the target when you hit the space key. You can toggle the PV by clicking on the sprite.

  • I agree, PixelRebirth. Hopefully that example will help him realize these things are simple...

    Cristi, from speaking with you in chat and seeing your forum posts, you seem to think everything needs to be super complicated. I'd suggest you go check out the Ghost Shooter tutorial before you try to port your whole game from VB and just get confused with needless complexity. You'll save yourself a LOT of trouble if you learn how Construct works before trying to do your port.

  • Thank you for the sample and the advices.

    Problem is solved.

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