auto generating new characters?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

auto generating new characters?

#1 Post by cedes »

Basically, I want there to be a group of random npcs, each with differences also created by random.

So I want to generate a few at a time, so basically they have a range of age, health, abilities, etc.
So can I generate npc2 if I have a npc1, and so on and so forth. Is there than an easier way than this?
Like "generate new npc" and it'd more onto npc3 from two and all.
Also, I'm very bad with python and coding!

Code: Select all

label group_start:
    
    call npc_name
    call count_npc
    
    call npc_name
    call count_npc
    
    call npc_name
    call count_npc
    
    call npc_name
    call count_npc
    
    call npc_name
    call count_npc
    
    return
       
label count_npc:
    if npc_count == 4:
        $ npc5_first_name, npc5_last_name = npc_first_name,npc_last_name
        $npc_count += 1
        
    elif npc_count == 3:
        $ npc4_first_name, npc4_last_name = npc_first_name,npc_last_name
        $npc_count += 1

    elif npc_count == 2:
        $ npc3_first_name, npc3_last_name = npc_first_name,npc_last_name
        $npc_count += 1
        
    elif npc_count == 1:
        $ npc2_first_name, npc2_last_name = npc_first_name,npc_last_name
        $npc_count += 1
        
    elif npc_count == 0:
        $ npc1_first_name, npc1_last_name = npc_first_name,npc_last_name
        $npc_count += 1

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: auto generating new characters?

#2 Post by kivik »

Do you have a list of different names for them? Or are they all supposed to have the same name? Or are they meant to be random?

Do you have the class code for your characters? I'm conscious you said you're bad with coding so I don't want to give you example codes that doesn't fit your requirements and further confuse you. Also, your mentioned random abilities, we need to see how the abilities work.

Instead I'll give you pseudo code for now (pseudo code isn't real code and cannot be used, it's just to demonstrate the concept):

Code: Select all

init python:
    def make_new_npc():
        npc = cNPC(
            renpy.random.choice(npc_names)["firstname"],
            renpy.random.choice(npc_names)["surname"],
            renpy.random.choice(range(16,60)),
            renpy.random.choice(range(100,200)))
            return npc

label group_start:
    npcs = []
    for i in range(0,5):
        npcs.append(make_new_npc())
    return

Post Reply

Who is online

Users browsing this forum: DewyNebula