I’m creating this game where players can pick their character’s first and last name. When the menu is first loaded up I want names to be randomly generated for the character. If the player doesn’t like the names they can either type in their own or click first name to randomly generate a new first name (the same for last name).
The issue is that I don’t know how to implement this and I would greatly appreciate any suggestions.
from random import shuffle
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
names = ['Bob', ....]
used = []
agents = 5
if agents > len(names):
print('o no dat is no goodz')
for i in range(agents):
actor =own.scene.addObject('actor',own,0)
shuffle(names)
go=0
try=0
while go==0:
if names(0) not in used:
actor.name =names(0)
used.append(names(0))
go=1
else:
if try<len(names):
shuffle(names)
try+=1
else:
print('o geeez')
go=-1
actor.name = 'potato'
why shuffle a list, if you can pick a random entry?
from random import choice
names = ["Bob","Jon","Frank"]
print(choice(names))
anyway…
To create real random names
from random import choice
def name_generator():
vowels = ['a','e','i','o','u','y']
consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']
name_length = 6
name = ''
for i in range(name_length):
characters = choice(['vowels','consonants'])
char = choice(characters)
if not name:
name += char
elif name[-1] in consonants:
name += choice(vowels)
elif name[-1] in vowels:
name += choice(consonants)
else:
name += char
print(name)
What cotaks said is the “procedural” way of generating names. They are not going to make sense but will be pronounceable. For example: egakilom. or tofuti. Completley random but pronouncable. I implemented this concept into my BGMC 22 game Every Man’s Sky
Instead of using the procedural method I had wanted the program to randomly pick from a list of names like what TheDave posted. I tried to change the .blend file that Cotaks created to fit this but I couldn’t figure out how to do it correctly.
Also, instead of changing the first name with the left click and the last name with the right click. I want to be able to just left click on each.