Randomly Generate a Name?

Get help using Construct 2

Post » Mon Sep 30, 2013 3:07 am

How do I randomly generate a name using C2?
B
9
S
3
G
1
Posts: 191
Reputation: 1,725

Post » Mon Sep 30, 2013 9:19 am

Could you be more specific?
Do you have a list of names you want to randomly pick one of?
Would you like to generate the name from random syllables?
Is "Q1hm5z&" an acceptable name?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Sep 30, 2013 4:25 pm

It doesn't matter. I could probably modify the script for my purposes.

I figure Q1hm5z& would be useful at some point in my programming travels.
B
9
S
3
G
1
Posts: 191
Reputation: 1,725

Post » Mon Sep 30, 2013 4:35 pm

The system expressions choose() and random() are probably what your looking for, you can find out more about them in the manual.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Sep 30, 2013 4:39 pm

choose ("Adam", "Bernard", "Cecil", "Doark", "Effreim", "Figgy", "Hanook")

etc.
B
18
S
7
G
1
Posts: 783
Reputation: 4,237

Post » Mon Sep 30, 2013 5:09 pm

Interesting. Can I pair the choose expression with an array? May I have an example?

At the very least, I think I could vary the length of the name, by using random() and loops, correct?ryackov2013-09-30 17:10:21
B
9
S
3
G
1
Posts: 191
Reputation: 1,725

Post » Mon Sep 30, 2013 5:26 pm

Let's assume you have an array filled with the all the possible characters on it's X axis. In pseudo-code:

Var Name = ""
For Loop: from 1 to However many characters you want the name
    Add Array.at(floor(random(Array.Width))) to Name

If it were me, I wouldn't use individual letters, I would set up a system that alternates between consonant groups (e.g. str,th,v,gh,s,wr,r,ph) and vowel groups (e.g. a,ou,ea,ay,oo,ai). It's more work, but yields more natural results.
    zatyka2013-09-30 17:39:41
B
63
S
19
G
8
Posts: 341
Reputation: 12,130

Post » Mon Sep 30, 2013 6:17 pm

I see, I suppose the best way to make names and then add them to another array would be add Var Name to an array?
B
9
S
3
G
1
Posts: 191
Reputation: 1,725

Post » Mon Sep 30, 2013 7:27 pm

You could do that. You could also generate the random names directly in an array.

Let's assume you have 2 arrays:
Characters - An array with all the possible characters of a name along its X axis.
Names - A array you want to populate with random names along its X axis.

For Each X Element in Names:
   Set value at Names.curx to ""
   For Loop: from 1 to However many characters you want the name
       Set value at Names.curx to Names.CurValue & Characters.at(floor(random(Characters.Width)))


B
63
S
19
G
8
Posts: 341
Reputation: 12,130


Return to How do I....?

Who is online

Users browsing this forum: charliesan763 and 16 guests