Picking SpriteFont objects by Text instance var

Get help using Construct 2

Post » Thu Jun 12, 2014 2:53 pm

Something that I thought would be trivial has taken me some trouble to work out. I have a number of SpriteFont objects in a layout and I'm trying to set their text individually. I have a Text instance variable in my SpriteFont object called something like WhatTextIsThis and setting each instance to "score1", "score2" or similar. When I try and pick an instance by evaluating SpriteFont.WhatTextIsThis = "score1" (for example) I get no objects picked. I tried lots of things and finally decided to use a simple numbering scheme, which worked immediately. What would be the problem with using Text in this case? I double checked that I'm comparing the correct text. Thanks.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jun 12, 2014 3:56 pm

Not sure what the problem is but using text works so you have overlooked something.

Did you add the instance variable as a "string" since "score1" is not a number if you use =score1 and add the instance variable as a number it won't be equal.

A version working using "score1" as a variable.

multispritefonts.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Thu Jun 12, 2014 10:26 pm

Thanks for that. Yes definitely a Text instance variable, just double checked. I'll check your sample and post back if and when I work out what I've done wrong. BTW as a test I changed the evaluation to use <> instead of = and *all* instances were picked.

Edit: Ok looking closer at your sample, I noticed that you don't have quotes around your text in the initial values. To me it was intuitive to use quotes as it's a string, but anyway! Thanks for helping me see this. :)

Edit 2: And also I had a redundant 'pick by evaluate' condition instead of a simple Compare Instance Variable condition.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jun 13, 2014 2:35 am

Just a final note.. The Construct editor puts an initial value of "" for Text instance variables, which is obviously misleading and should probably be removed.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: hrisnz and 16 guests