How do I get a random letter of the alphabet to populate a text box?

0 favourites
  • 5 posts
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • I am a newbie and attempting to create a word game in which a random pairing of initials will be generated for players to submit an answer. For instance, TK = Topeka, Kansas as a correct answer. I am attempting to develop the logic to compare the letter pairings to player input and am starting with one random letter at a time I am using ChatGPT 4.0 as a guide and quite frankly, it seems to have me chasing my tail.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you mean random predetermined pairs then you can store them in an array where first column is the pair like TK, and second column is the answer. To pick at random you can use random(x) to choose a random row number of the array where x is the number of rows. When TK is chosen for example you can compare the text input in the textbox against the answer in column 2, if I understood the game correctly.

  • Yeah, the question isn't very clear. To get a random letter of the alphabet you can use this code:

    Variable alphabet = ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    Set letter to mid(alphabet, random(len(alphabet)), 1)
    

    If you have a list of names/states and you want to pick one of them at random and display its first letter you can do something like this:

    Variable states = Alabama,Alaska,Colorado,Michigan
    
    Set randomState to tokenat(states, random(tokencount(states,",")), ",")
    Set letter to left(randomState, 1)
    

    You can find all these expressions in the documentation:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/text

  • Sorry about the confusion. At the start of the game, the system should generate five pairs of letters in boxes. I thought starting with one letter and one row would be the easiest way to figure out the logic.

    I've gotten as far as creating a layout and naming boxes. Someone much younger and smarter than me told me this would be easy to build on this platform. I think I'm in over my head. The world needs ditchdiggers, too.

  • Sorry about the confusion. At the start of the game, the system should generate five pairs of letters in boxes. I thought starting with one letter and one row would be the easiest way to figure out the logic.

    I've gotten as far as creating a layout and naming boxes. Someone much younger and smarter than me told me this would be easy to build on this platform. I think I'm in over my head. The world needs ditchdiggers, too.

    Many years ago I thought I could never code/make games. I was 100% convinced of it, but some people around me told me it was possible, and I was lucky to believe them (I have since worked on many projects as a programmer and web dev). I'm telling you right now, you can do this, and we are all here to help you.

    Now, concerning your specific issue, firstly I'd suggest going through dop2000 idea, it's very informative and generally useful.

    Secondly, if I understand correctly, I would make some empty String variables to be the containers for your pairs.

    Then I'd make dop2000 code into a function that returns one of the random letters, and use a "repeat" or "for" loop to run the function as many times as you need and populate the empty strings.

    All the best! You can do this.

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