How do I pick several UID instances at the same time

0 favourites
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Is possible to use a event to pick several instances at the same time using the UID of each one and then compare frame number and apply an action after?

    Like this?

    Event:
    Pick instance with UID 0
    Pick instance with UID 1
    Pick instance with UID 2
    Pick instance with UID 3
    
    Subevent:                                  
    Animation frame = 3 
    
    Action:
    Set variable to 1[/code:1ajg2q4i]
    
    Thanks
  • You could do this:

    Event:
    Repeat 4 times
    Pick instance with UID int(tokenat("0,1,2,3", loopindex, ","))
    
    Subevent:                                 
    Animation frame = 3
    
    Action:
    Set variable to 1[/code:15uf40zs]
  • Simpler pick:

    Pick instance by evaluating instance.UID >=0 && instance.UID <=3

  • ....or even

    Pick instance by evaluating instance.IID <= 3

    I think you might be confusing UID and IID. The UID for each different instance or object is unique, so unless your objects are the first 4 that were created on any layout then this will return nil. There are no IIDs (or UIDs) <0, so you don't need to check for > 0. If you use IID this way you will pick (in this example) the first 4 of your instances that were created. I haven't tested this so I could be mistaken....

  • R0J0hound: Thanks for suggesting this solution. I used "tokenat" a few times. I didn't know how to use it in this situation. Many thanks. One doubt: if the UIDs are not in sequence, can I continue to use the "tokenat"?

    blackhornet: Thank you for this simple solution. But how can I do if the UIDs are not in sequence. Maybe something like this:

    Pick instance by evaluating instance.UID=0 && instance.UID =3 && instance.UID =5 && instance.UID =9
    [/code:3qdwh9qz]
    

    Colludium: I understood your explanation and I intend to test it, but before I need to know how can I do if the UIDs are not in sequence. Thank you.

  • That's the problem with absolute examples; you get absolute solutions.

    You'd be better off flagging the instance you care about in some other manner (instance variable) so you can pick them with a simpler test, rather than with a list of UIDs.

  • I'm not sure exactly what you want to test for so I'll try and help as best I can. Each object is assigned a UID and an IID when it is created, whether that's in the editor (seen when the layout is loaded, but you can check in the properties bar) or whenever you create an object. I don't know if UIDs are reused after an object is destroyed but I suspect not. IIDs are reused, so if you destroy the first 5 objects that were created out of 8 total, the last 3 will be renumbered IID from 5-7 to 0-2. Here's the manual info.

  • That's the problem with absolute examples; you get absolute solutions.

    You'd be better off flagging the instance you care about in some other manner (instance variable) so you can pick them with a simpler test, rather than with a list of UIDs.

    blackhornet: Instance variables is an alternative but I'm using lots of istances and I need to check just 4~10. The problem is that not always the same instances. Do you know if the example that I wrote before works?

    Pick instance by evaluating instance.UID=0 && instance.UID =3 && instance.UID =5 && instance.UID =9[/code:1bpg7jei]
  • I'm not sure exactly what you want to test for so I'll try and help as best I can. Each object is assigned a UID and an IID when it is created, whether that's in the editor (seen when the layout is loaded, but you can check in the properties bar) or whenever you create an object. I don't know if UIDs are reused after an object is destroyed but I suspect not. IIDs are reused, so if you destroy the first 5 objects that were created out of 8 total, the last 3 will be renumbered IID from 5-7 to 0-2. Here's the manual info.

    Colludium: I just need to check the frame number of some specific instances

  • Yes, that will work. I'm just suggesting that you do something like adding an instance variable, lets say 'Special', then you set the instances you care about to '1', and do a Pick instance.Special=1. This is a cleaner solution, and more versatile than hardcoding UIDs. It's your call.

  • blackhornet: Okay I'll follow your suggestion. Thank you for your assistance.

  • You could do this:

    > Event:
    Repeat 4 times
    Pick instance with UID int(tokenat("0,1,2,3", loopindex, ","))
    
    Subevent:                                 
    Animation frame = 3
    
    Action:
    Set variable to 1[/code:3pzsd4qp]
    

    R0J0hound: I tried this solution using non-sequential numbers (0,3,7,9,13) and if I click on one of these instances the value of the variable is changed when in fact I need all the related instances have been selected to change this value . What can I do in this case? Thank you.

  • You should never hard code UIDs or IIDs. You don't want to rely on the random chance that they will be the same between sessions.

    blackhornet 's solution is the best, in my opinion.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Wastrel

    I actually thought about using the blackhornet's solution, but this will force me to create a layout for each level. I have 55 squares on the screen and they are combined to generate drawings of different numbers. I will not always use the same squares. If I use a instance variable, I have to change the value of this variable for each combination. So it would be better to access the instances through UID.

  • RenatoB , yet another way would be to push the uid you want to check in an array, then for each x, pick uid at array.at(curx) and compare whatever

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