Random Name Generator
Posted: Mon Apr 28, 2014 11:55 pm
I was messing around and I thought some could use this example. This code is to create a name out of a list of possible outcomes. It also serves as an example on how to use a list or classes/functions.
After this, we move on to create the generator class somewhere else in the code.
Now, there are many uses to this, but if you want to use it for NPCs and whatnot you can do this:
You can create as many generators as needed inside the class (depending on race, gender, species, etc), you could have gen.femalename() or even gen.dogname(), just make sure you create an specific list each time (So femalename() doesn't take anything from the malename() list). It can also have as many parts as needed (Just name or three names).
Anyways, that's that, hope this helps you. If you have any trouble with this just let me know.
Code: Select all
init:
#First we set up some variables:
$ gen_name = "" #The name that will appear
#Then we create the list with possible names.
$ name_list = ["Paul", "John", "George", "Ringo"]
$ l_name_list = ["McCartney", "Lennon", "Harrison", "Starr"]
Code: Select all
init python:
class GENERATOR:
def malename(self):
generatedname = renpy.random.choice(name_list)
#Take one name from the name_list list and store it at generatedname
generatedlastname = renpy.random.choice(l_name_list)
#Ditto
store.gen_name = generatedname + " " + generatedlastname
#Show the result of putting both together and store it on the gen_name variable.
#If not for the " " part we could get RingoStarr
Code: Select all
define e = DynamicCharacter("gen_name")
#This means the character name will be the one stored at gen_name
label start:
python:
gen = GENERATOR()
#This lets us use the GENERATOR class as just "gen"
$ gen.malename()
#At this point the game will run what you made it do on the malename
#function of the GENERATOR (now just gen) class. With that, it will
#create a name out both lists nad store it at gen_name
e "Now my name is [gen_name]"
Anyways, that's that, hope this helps you. If you have any trouble with this just let me know.