How do I make a name picker?

Get help using Construct 2

Post » Fri Dec 06, 2013 9:15 pm

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
B
15
S
3
G
1
Posts: 7
Reputation: 1,547

Post » Sat Dec 07, 2013 1:59 am

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.
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Sat Dec 07, 2013 2:41 am

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)))mindfaQ2013-12-07 02:47:32
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat Dec 07, 2013 3:27 am

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
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,471

Post » Sat Dec 07, 2013 4:08 am

Thank you guys so much for your help. I will post the finished product soon.
B
15
S
3
G
1
Posts: 7
Reputation: 1,547

Post » Sat Dec 07, 2013 7:48 am

Or the simplest:

choose("name1","name2","name3","name4","name5","name6")
B
239
S
62
G
33
Posts: 903
Reputation: 40,562


Return to How do I....?

Who is online

Users browsing this forum: koops, Slug101 and 6 guests