Pick by UID in an expression

0 favourites
  • 9 posts
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • I know you can select the IID by this: sprite(2).x

    But is there a way to do that but for UID instead? I have been going through the documentation and not coming up with any luck.

  • Sprite.uid

  • There are also pick by UID actions as well.

  • BluePhaze - Oh sorry I should be more clear: I want to be able to select it followed by more detail. So if I type sprite(2).x, I will get the X location of the 3rd instance of 'sprite'. However if I use sprite.UID, that's it! I can't then select its X, Y or variables. This is important because I don't want to actually pick the object, just reference its information.

  • Tobye - I had to do something similar to this, and while this might be a terrible way to handle it, it worked for what I needed ;)

    I started by creating a dictionary to hold UID-IID pairs, so when I created an object, I added an entry to the dictionary with the UID as the key, and IID as the value. Then retrieving information from that object during an expression was something like:

    sprite(Dictionary.Get(aUID)).X

    I ran into some problems when I removed objects though, as that can change the IID causing the info in the dictionary to be incorrect. To fix it, I just ran a loop that reset the IIDs for the objects stored in the dictionary.

    Like I said, maybe not the right way to do it, but it worked for my needs. Of course if I find out there's already an expression in there for this, I'll lose it ;)

  • rogueNoodle - Thanks for the idea, I mixed it a little with what I was currently working with and it seems to work okay now. I stored the IDs in local variables instead of a dictionary though which makes things much neater, but might not work for you if it's a long running system.

    I also was concerned about the IDs changing as things were destroyed, but it's all contained within a function call for now and I was able to work the creations and destructions in a way that it isn't currently a problem. But, if later on it does become a problem I'm scared it'll take me a long time to figure it out! xD Since the objects I'm dealing with are dictionaries, there no visual issue I can notice.

    Let me know if you do find a simple expression for this!

  • The best way is to use a local variable and a subevent. Use 'Pick by UID' in a subevent, store sprite.X in the local variable, then after that event finishes the local variable has the X co-ordinate of the sprite with a specific UID in it.

  • Tobye If you use the pick by UID option you can access the specific object that the UID refers to and all it's variables in that same event, just use sub events within that event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • BluePhaze - Yeah the problem I was having was tricky though, because I wanted to add the variable information of one instance to another instance of the same object. So, if I pick by UID I can access it's info, but then I need to pick the other instance before I can apply the info, so the UID picked instance is longer picked. So if there was a way to just select by UID in an expression I would get the information and be able to apply it straight away, without any of the extra fuss I have in there right now.

    Ashley has a good solution, thanks! It takes a little more work to setup than what I had (as it's a long list of variables), but it's less liable to run into problems.

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