How to do a question and multiple answers? akin to Huniepop

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
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

How to do a question and multiple answers? akin to Huniepop

#1 Post by LiveTurkey »

Hello all, I have a sort of difficult question.

I'm creating a dating simulator. There are 11 different characters. When you talk to a character they can ask you a question. For example "What do you like to do for fun". There are 11 possible answers to this question. One that each character would like to hear.

I want to have it set up so that when you ask the character a question you are given the correct answer (the one that matches their personalities) and two incorrect answers (The one that matches some other characters personality )

The way I was thinking of doing it is that each character has an ID from 1 to 11. Then each question has a table of answers also from 1 to 11. The correct answer matches the character's ID in the table. So you would display the answer for the number that matches the ID and two answers for random number from 1 to 11 except for the ID one.

Does anyone know how to implement this. I have no idea where to even start. I don't even know how to get a data structure going in renpy. I would assume a simple array would work but I could also use a hash with the IDs as keys.

Are there any renpy games that have implemented this?

Any help at all would be awesome.

Thanks.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How to do a question and multiple answers? akin to Hunie

#2 Post by philat »

Your initial idea should work fine. Renpy can construct menus out of lists. (https://www.renpy.org/doc/html/statemen ... splay_menu )

You can generate random lists out of an initial list using random choices. Use renpy.random instead of built-in python random to ensure compatibility with rollback.

Data structures themselves are just pure python -- and rather than going into the details here, there are better resources for learning straight python a google search away.

Basic framework would be something like the following. Do note that this is completely off the top of my head and not at all refined to be elegant. It's meant to set out the basic processes and some of the list methods you probably want to work with just to get you pointed in a vague general directipn. That said, it will work - albeit in an ugly manner.

Code: Select all

default fixed_answer_list = ["A", "B", "C", "D", "E"]
default temp_answer_list = fixed_answer_list[:] # copies fixed_answer_list

default rand_list = []


init 2 python:

    def generate_random_menu(caption, character):
        global rand_list
        global temp_answer_list
        global fixed_answer_list

        rand_list.append((caption, None)) # show right answer as unclickable menu item for sake of testing
        rand_list.append((character, True)) # add right answer with return value of True
        temp_answer_list.remove(character) # remove right answer
        rand_list.append( ( temp_answer_list.pop(renpy.random.randint(0, 3)), False)) # pop removes and returns random answer from remaining list, return value False
        rand_list.append( ( temp_answer_list.pop(renpy.random.randint(0, 2)), False)) # note that the list is shorter so randint is now one of 0, 1, 2
        temp_answer_list = fixed_answer_list[:] # reset temp_answer_list


label start:
    $ rand_list = [] # reset rand_list
    $ testvar= renpy.random.choice(fixed_answer_list) # randomly choose element from fixed answer list to test
    $ generate_random_menu(testvar, testvar) # create random list
    $ user_answer = menu(rand_list) # show menu and return value to user_answer
    if user_answer:
       "Right answer."
    else:
       "Wrong answer."

    jump testing

User avatar
Mammon
Miko-Class Veteran
Posts: 712
Joined: Sat Nov 07, 2015 3:09 pm
Completed: Pervert&Yandere, Stalker&Yandere
Projects: Roses Of The Thorn Prince
Contact:

Re: How to do a question and multiple answers? akin to Hunie

#3 Post by Mammon »

I'm not sure if I understand correctly what you mean, because it seems that what you're asking can be handled with basic persistents, so I'd do the following:

Code: Select all

<Girl A's question>
Choice girl A
$ girl_A_pref = +1
A 'Good answer'
<Choices girl B-K similar to above with A swapped. So each girl has their own persistent, and each persistent defined at the beginning of the game as $ girl_X_pref = 0.>
<After a 5 choices>
if girl_A_pref => 3:
A 'You picked me over the others.'
May be a few small errors considering I haven't coded in a while and never really used the => function before, but it should mostly work.
ImageImageImage

Want some CC sprites?

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: How to do a question and multiple answers? akin to Hunie

#4 Post by LiveTurkey »

philat wrote:Your initial idea should work fine. Renpy can construct menus out of lists.
.
.
.
.

Code: Select all

label start:
    $ rand_list = [] # reset rand_list
    $ testvar= renpy.random.choice(fixed_answer_list) # randomly choose element from fixed answer list to test
    $ generate_random_menu(testvar, testvar) # create random list
    $ user_answer = menu(rand_list) # show menu and return value to user_answer
    if user_answer:
       "Right answer."
    else:
       "Wrong answer."

    jump testing
Wow dude! You are awesome. Thanks so much. I have one question if you don't mind.

I had a bunch of questions here but I figured everything out! Thanks again.

Post Reply

Who is online

Users browsing this forum: 3N16M4, Bing [Bot]