Call text from random integer selection

0 favourites
  • 7 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hey all,

    I want to generate a number between 1 and 20, and set a textbox to a value based on what number is generated.

    In a hypothetical pseudo code world, I would want:

    Integer= int(random(1,20))

    Set Text1 = Text.Integer

    I might not be going about this in the correct way. Is there any way I can put 20 values into the textbox as instance variables and count from 1 - 20?



  • For clarification, if I could name a text variable "1" or "2" etc. and save text to it:

    Set Textbox = 1.Text

    Set Textbox = 2.Text

    Set Textbox = RandomInteger.Text

    Is there any way to set the current key in a dictionary to a random integer? So it generates "17" and it reads the 17th key of the dictionary?

  • Okay, sorry if my question wasn't clear.

    A user touches a sprite. I want text from a textbank of 1 - 20 to appear. I have a dictionary with 20 text entries in it. How can I randomly select a line of text from the dictionary?

  • floor(random(20)) will give you a random number in the range [0,19].

    So if your dictionary keys are "text_0", "text_1", etc. you can get a random one with:

    Dictionary.Get("text_" & floor(random(20)))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • okay, so I figured out what was wrong. My text variables are set as Q1, Q2, Q3, Q4, etc. I had


    Add "Q" & str(Dictionary.RandomNumber)to "Text"

    that generated 1, 2, 3, 4, 5! The "Q" wasn't even being added on! So I literally wrote

    Dictionary.setvalue "Q" and that did not work either. I have no idea why.

    So finally I set the default value to the text as Q and just added to that. Wow. Thanks for the help Ramones

  • Okay. I have instance variables Q1, Q2, Q3 with text saved...

    Dictionary.Get("Q1") returns "0"

    This program is seriously bugged. I'm not joking.


    Literally cannot imagine what I'm doing wrong

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