0 Favourites

How do I make a name picker?

  • Hey Guys,

    I am a total noob when it comes to programming with construct.

    The simple task I would like to create is a Name picker. Not a random name generator. But a program that lets you populate names into a field, hit a button and it spits out one of the pre-writen names you put into it.

    I have no idea where to start. Any help would be great.

    Thanks

  • I think you want Dictionaries (check the manual). I guess create textboxes for text entry and whenever text has been entered and confirmed, add it to a list of string variables stored in Dictionary form. Then when you select the button to spit out a random name, choose one of the stored strings or choose a random number which is assigned to a random string via Dictionaries.

  • just another alternative

    create a text variable textvar = Alex;John;Stephen;Helen;Tina;Josephine

    go get a random name from this use set name to tokenat(textvar,floor(random(tokencount(textvar,";"))),";")

    You also can add a simple input into the variable if you want.

    like set textvar to textvar&";"&textbox.text

    or another:

    array:

    (start with 0,1,1 sized array)

    when entering text: push array x back value = textbox.text

    when selecting a random name: set name to array.at(floor(random(array.width)))

  • Have a look at arrays , and the random() expression , the routine would be populating a 1-dimensionnal array with strings , and then picking a random expression from the array via ;

    Array.At(random(0, Array.Width - 1))

    Important ; Arrays start at 0 , and not one , but the width is 1-based that's why I put Array.Width - 1

  • Thank you guys so much for your help. I will post the finished product soon.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Or the simplest:

    choose("name1","name2","name3","name4","name5","name6")

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
167 14,497
DMT2005's avatar
DMT2005
Unread sticky
1 Favourites
C2 Games made with CocoonIO
136 89,824
minhcuong's avatar
minhcuong
Unread hot topic
99 10,138
karshinkoff's avatar
karshinkoff