How do I know which instance has which IID?

0 favourites
  • If I've placed 5 objects (say, of Object type 'Cat') on a layer, how can I know which Cat has which IID? Or to put it another way, if I pick Cat instance 1, how do I know which Cat I'm picking?

    The IID for a particular Cat instance is not shown in the Properties Bar (because the IID is allocated at runtime?), so how can I pick it with certainty when I add a condition that will target an action on that Cat instance alone?

  • If you have a cat object with platform behavior and a boolean instance variable named 'selected'

    You can do that:

    System: On start of layout
      -> Cat: Start ignoring Platform user input
    Mouse: On left cliced on Cat
      -> Cat: Set selected to True
    Mouse: On right click
    Cat: is Selected
      -> Cat: Jump

    If you click on a cat and then right click, only the cat on which you clicked will jump.

  • Yann thanks for the instant reply!

    I can see that that would work when there's user interaction with the cats. But what if there's no user interaction and it's the system that's doing the selection?

    For instance (!), if Cat objects have a Boolean 'favorite' instance variable that's set by the system for one particular cat when a new level is reached, or the game is replayed, or a certain time has passed, how can I add a condition that targets that Cat instance (and that alone) ?

  • System: On start of layout
    .. System : Pick random Cat Instance
       -> Cat: Set boolean to true
    
    Cat: is  boolean
      -> Cat: This is the cat you want
    

    Assuming all cats Boolean are set to false on start of the layout.

    This is the usual picking with variable.

  • Kyatric Thanks for your rapid response!

    ... but I want to get the system to pick a particular Cat instance (say, the black one), not a random instance. How do I do that? How do I know what IID the black cat has?

  • I think we are running a bit in circle, you should explain a bit more what is your game.

  • Same thing actualy.

    Compare the value of an instance variable that you set in the IDE. (ex: instance variable index, value 0 to 4 (for 5 instances))

    Or they have different animation frames ?

    Compare the animation frame.

    It's all the same logic that picks only the instances that match with the condition.

    A look back at how events work might be useful here.

  • Kyatric "Compare the value of an instance variable that you set in the IDE".

    Thanks, I'm aware that you can do it by comparing instance variables, but that seems to me to be a roundabout way of identifying a particular instance in a system condition.

    I was hoping that there's some more direct way of knowing the IID of each instance and being able to use that.

    For example, let's say my layout has a cat in each corner and a cat in the centre. Is there any way I can tell what the IID is of the cat in the centre?

    In JavaScript, they'd each have different names (e.g. centreCat, topLeftCat, ...) and I could say 'centreCat.favorite = true' (with all the cornerCats having their 'favorite' Boolean set to 'false').

    So another way of asking my question is:

    How do I program 'centreCat.favorite = true' in Construct 2?

  • In my opinion you're asking the wrong question.

    But I don't mean to be rude :D

    I see many ways to do what you ask, but all these ways aren't the best way depending on what you want to use your cat for.

    If you want to pick a cat with the mouse and make it do something my solution works well.

    If you want to apply some action on a black cat but not on the other ones, you can use their animation frame or name ('cause it would be different to show differnt colors') to pick them.

    If you want to pick the centered cat, you can compare it's position.

    If you want to pick a cat precisely, amongst the same kind of cats (same graphics) whereever it is...

    First let me say that I don't see the point to be so specific.

    But let say you want to be, you just have to do what Kyat said and assign ID in instance variables at runtime.

    Also, if you want to memorize a picking for later uses. Let say you selected one cat at the start of the game, the cat gets hidden under mugs and the mugs get shuffled (like these street performance you know?) you can maybe store its UID in a global variable at runtime and pick by UID afterward.

    But in this example I would just simply set a boolean to true on this specific cat when you select it.

    Now I hope you understand why I said that you should explain a bit more about your game. We need context to provide the optimal answer.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • IIDs are not constant - they change as you destroy and create objects, so you can never be certain that an IID refers to a specific instance.

    You probably want to use UIDs instead, which permanently refer to a single instance. More info in the manual.

  • Thanks for bearing with me, folks!

    I take it from what you say is that there's no way in Construct 2 of directly doing what I can do in JavaScript with " 'centreCat.favorite = true' ".

    And now that I've confirmed (I think!) that there's no direct and simple way of doing this that I've missed, I'll work on giving a fuller example, together with what seem to me to be the workarounds that you've suggested.

    I'll be back and hope you can bear with me a bit longer :)

  • Demo capx

    Run as it is, you see no text in the layout.

    Go in the event sheet, right click on any group, set as active it does pick the black cat.

    It does since in the IDE, I've setted the animation frame to be singular, an instance variable number and an instance variable boolean to be singular (there's only one black cat (anim frame = 1), favorite=true, fave = 1).

    This is not a workaround, this is how events work.

    At least that's the setting and the solution how I understand it from everything you described so far.

  • Kyatric Lovely work ! Mille remerciements !

    I'm going to have a close look at your demo later today (8:20am here in NZ, and I have to go out on a job now).

    Your demo capx gives me a much better way of explaining my query and then going on to look at possible solutions (including yours, of course).

    I really appreciate the attention and effort you're giving to this issue.

  • Here're a couple of demos of my own. First, a reminder of what I'd like to do:

    To have a means of identifying each particular cat at the point of placing them on the layout.

    I can do that in JavaScript (or any OO language) by giving each a unique instance name e.g. 'centreCat'.

    I can't see any way of doing that in Construct 2. That's why I call any way of achieving the same outcome a 'workaround'.

    This capx shows one workaround (following suggestions by Kyatric and Yann) - and one example of why I need to have a means of identifying a particular cat at the point of placing it on the layout. (Thanks again to Kyatric for his graphical interpretation of my verbal description!)

    When the game is reset (e.g. when the game is over and we want to play it again), I need to revert to making the centre cat (black) the favourite, by setting its 'favourite' Boolean instance variable to 'true'.

    Hence my need to be able to identify that cat at the point of placing it on the layout. And hence this workaround:

    Give each cat an additional Boolean instance variable: 'colour'. When resetting, use the 'colour' Boolean to pick the centre cat and set its 'favourite' Boolean to 'true' (having reset all the others to 'false').

    This capx shows another workaround (following suggestions by Ashley and Yann): At the outset, I save the centre cat's UID in a global variable 'CentreCatFavourite'. When resetting, I pick that cat instance with its UID and set its 'favourite' Boolean to 'true'.

    Thanks again for bearing with me!

  • If you set the instance variable of a particular instance in the property panel at edit time, each time you reload the layout the instance variable of this object will be reset to this value.

    So if you always want the center cat to be selected on start of layout, you just need to set it at edittime.

    Didn't look at your capx though, but if I understood your post well, all your questions have been answered?

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