0 Favourites

Selecting by UID

  • I've searched the forum and for the life of me I can't find it anywhere... can somebody advise me on how I can Set text of 1 instance to something, as I'm using Sprite Font, I don't want to create new ones due to the size (please advise if I'm doing it wrong).

    Currently I have this code, which I thought would work, but apparently not:

    System | "Object with UID 53 exists" > "Set text to "Level " & level

  • If you have a bunch of text objects and you want each to be set to something different, you can give it an instance variable, so you can select the object easily later. For example:

    Textobject variable "name" = "level" > "Set text to "Level " & level

    Textobject variable "name" = "score" > "Set text to "Score " & score

    Textobject variable "name" = "lives" > "Set text to "Lives " & lives

    etc

    [quote:3vqw4dtu]I don't want to create new ones due to the size

    What's this supposed to mean?

  • If you have a bunch of text objects and you want each to be set to something different, you can give it an instance variable, so you can select the object easily later. For example:

    Textobject variable "name" = "level" > "Set text to "Level " & level

    Textobject variable "name" = "score" > "Set text to "Score " & score

    Textobject variable "name" = "lives" > "Set text to "Lives " & lives

    etc

    [quote:2hjmrwxg]I don't want to create new ones due to the size

    What's this supposed to mean?

    Not sure if I've missed something, but assigning an instance variable will add it to all occurrences of it, so it still won't uniquely identify them.

    And by "due to the size", I mean if I add multiple Sprite Fonts it will increase the memory useage... unless I'm doing it wrong. I'm new to it but learning fast

    Thanks

  • My solution would be to give the SpriteFont an instance variable.

    Then system > compare instance variable > SpriteFont > Variable = 1 | SpriteFont > set text

  • If you make a complete clone (rather than "clone type") it applies it to ALL of them so this would be impossible.

    I've found whatI wanted though... I was being stupid... there's a "Pick by unique ID" - Cant believe I didn't see it! D'oh. Sorry to waste everyones time

  • But yes, the method of comparing by instance variable (as a self-appointed ID) actually does work. You can of course set the initial value in the status bar for the object on the left of the editor and in a condition, check for if "instance variable = n" or whatever value.

  • Is that by doing a "Clone type" or a complete duplicate (Ctrl C > Ctrl V)? As from testing when I add the instance variable to one, it adds it to the other.

    It's now more out of interest as I've found the solution... so I'm more interested in learning more so I don't make silly mistakes again

  • Far as my own testing goes, it works for me with the instance variable, and I can make a capx if you need an example.

  • If you dont mind, that would be fantastic. Then when I break it I can upload it too

  • The variable is added to all copies, but you change the value of the variable independently

  • Ah okay, in that case no file is required, it makes Sence now, thanks everyone for your input

  • Here's a working example if you want anyway, with something to refer to to give you a clearer idea:

  • Relying on UID is not the best idea. The trick with instance variable works very well.

    In the example LaDestitute gave you actually check if the clicked object is the one you need. If you want to grab the instance directly from any place use the following:

    System > Pick by comparison

    first argument: spriteFont.instanceName

    second argument: {the name you set manually}

    Just be sure you have each instance name unique. Or it might be useful to have some of them named the same. For instance let's say you have a "credits" section in your game which is very long. You want to pin them to some drag&drop background sprite so user could scroll and see all the credits. Then you might set all the spritefonts instanceName value to "credits" and then pin them all with one event to the sprite.

    So basically with the instanceName variable you can pick the distinct instance of an object or some group of them.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • It'll also work with keyboard controls, such as for a top-down ARPG and checking if the player is overlapping/near a certain chest or interactive object.

  • Ah yes I'll change my statements to use the variable ID trick. Thanks all

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