0 Favourites

Picking SpriteFont objects by Text instance var

  • 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.

  • 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.

    [attachment=0:29ykiom3][/attachment:29ykiom3]

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
207 72,475
blackstr's avatar
blackstr
Unread hot topic
198 47,125
Zebbi's avatar
Zebbi
Unread hot topic
0 Favourites
[Plugin] tag text
188 25,447
RBuster's avatar
RBuster