Selecting by UID

Get help using Construct 2

Post » Sat Feb 27, 2016 8:39 pm

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
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sat Feb 27, 2016 8:49 pm

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

I don't want to create new ones due to the size

What's this supposed to mean?
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Sat Feb 27, 2016 9:04 pm

7Soul wrote: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

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
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sat Feb 27, 2016 9:46 pm

My solution would be to give the SpriteFont an instance variable.
Then system > compare instance variable > SpriteFont > Variable = 1 | SpriteFont > set text

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Sat Feb 27, 2016 11:25 pm

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 :-)
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sat Feb 27, 2016 11:28 pm

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.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

Post » Sat Feb 27, 2016 11:37 pm

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
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sun Feb 28, 2016 12:13 am

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.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

Post » Sun Feb 28, 2016 12:21 am

If you dont mind, that would be fantastic. Then when I break it I can upload it too ;-)
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sun Feb 28, 2016 3:21 am

The variable is added to all copies, but you change the value of the variable independently
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 20 guests