How do I set text to my desired characters without using choose?

0 favourites
  • 8 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Hello friends, please see the very simple attached example. I want the five text boxes to be replaced with 10,20,30,40,50 - in the order I typed them in the event sheet. I know I shouldn't be using choose, but I don't understand what to do.

    There is one text box, then four instances. All five have an instance variable, from 1 to 5.

    Many thanks for any assistance.

    dropbox.com/s/cssb1o2ib2nuh2y/test.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You mean you want to randomly set values 10,20,30,40,50 to five text boxes, without repeats?

    Try this:

    For Each TextBox Oredered By random(1)
    TextBox set text to (loopindex+1)*10
    

    If it doesn't need to be random, then it's even easier:

    TextBox set text to (Self.IID+1)*10
    
    
  • Thanks for your reply.

    No, there is only one original text box, then four instances. All five have an instance variable, from 1 to 5 (see c3p). I am using a click on a sprite to replace the values of all five at once. I click on the sprite and whatever I have typed in the event appears in the boxes, in order that they are listed. It could be anything:

    10, 20, 30, 40, 50

    3, 4.5, 9999, 21, 85

    .001, 750, 6, 1000, .23

    It currently works fine with 'choose', e.g.

    - Set text to choose (.001, 750, 6, 1000, .23)

    All five boxes get replaced with some number from the list, but I don't want choose, and I don't want random. I want all of them to fill the boxes, in the order that I list them.

  • The long way is to pick each instance and set text:

    TextBox var=1 : TextBox set text to "10"
    TextBox var=2 : TextBox set text to "20"
    TextBox var=3 : TextBox set text to "30"
    ...
    

    The compact way is this:

    TextBox set text to (self.var=1 ? "3" : self.var=2 ? "4.5" : self.var=3 ? "9" : self.var=4 ? "21" : "85")
    

    Another method:

    TextBox set text to tokenat(".001,750,6,1000,.23", self.var-1, ",")
    
  • The compact way is this:

    > TextBox set text to (self.var=1 ? "3" : self.var=2 ? "4.5" : self.var=3 ? "9" : self.var=4 ? "21" : "85")
    

    Another method:

    > TextBox set text to tokenat(".001,750,6,1000,.23", self.var-1, ",")
    

    This works great. Thanks so much. Very helpful! Token seems even more compact.

  • Can I ask what the -1 after the variable is doing? I don't really understand the token either, but I can read about that I'm sure.

  • Tokens start at index 0 (0,1,2,3,4) , and your first var is 1 (1,2,3,4,5), so all variables are being reduced by 1.

  • Tokens start at index 0 (0,1,2,3,4) , and your first var is 1 (1,2,3,4,5), so all variables are being reduced by 1.

    Thanks for that, now I understand. I plugged this method into the actual full project, where my first var is actually 0, and it worked fine after I deleted the -1, so that makes sense now. Thanks for taking the time to respond.

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