how to make a random choice against 2

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
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

how to make a random choice against 2

#1 Post by DragonKnight »

I'm just a newbi, so bear with me. I need to make a choice between 2 characters. A random choice, so I can play it one time and I get choice 1, and I play it a second time and get the same or choice 2.
Currently working on Taboo Hearts :D
Currently working on Forbidden :D


User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Re: how to make a random choice against 2

#3 Post by DragonKnight »

"The next day."
$ day_gone_by += 1
# return a random float between 0 and 1
#$ randfloat = renpy.random.random()
# return a random integer between 1 and 20
#$ d20roll = renpy.random.randint(1, 20)
# return a random element from a list
#$ randfruit = renpy.random.choice(['apple', 'orange', 'plum'])
if slept_alone == True:
$ randchara = renpy.random.choice(['m', 's'])
if randchara == m:
"Then m"
"Mom"
if randchara == s:
"Then s"
"Sis"
Ain't working out. It goes to "the next day" and it closes the page(in other words my vn goes straight to the title page)
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: how to make a random choice against 2

#4 Post by irredeemable »

What exactly are you trying to do? For one thing you need to use indentation, so the last part should look like:

Code: Select all

if slept_alone:
    $ randchara = renpy.random.choice(['m', 's'])
    if randchara == 'm':
        "Then m"
        "Mom"
    elif randchara == 's':
        "Then s"
        "Sis"
That's assuming you intended to simply display those strings in the dialogue box.

User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Re: how to make a random choice against 2

#5 Post by DragonKnight »

if slept_alone == True:
$ randchara = renpy.random.choice(['m', 's'])
if randchara == m:
"Then m"
"Mom"
if randchara == s:
"Then s"
"Sis"
if sis_slept == True:
"Sis"
"Sis!!!!"
if mom_slept == True:
"Mom"
"Mom!!!!"

"Mom told us what was happing"
not working. I got the spaces alright, just not gonna show up here
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: how to make a random choice against 2

#6 Post by irredeemable »

Again there's no indentation and you haven't set the if statements to test for a string. The first one, for example, is testing if the variable randchara is equal to the value of the variable m, which, presumably, does not exist.

User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Re: how to make a random choice against 2

#7 Post by DragonKnight »

I have the indent, but i doesn't show up here, I don/t know how to include the Code: Select All box, and thats the reason why it didn't show up. I took the code you offer and put in my game. The select all box. and i doesn't work. I know i'm doing something wrong, i just need to know what i'm doing wrong??
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

User avatar
Draziya
Regular
Posts: 70
Joined: Sun Nov 26, 2017 8:50 am
Completed: this was for you. [NaNoRenO 19], Acetylene [AceJam19], Ah!! My Roommate is a Succubus Hellbent on World [MonJam 18], I Don't Have A Clue [QRMJam 18], Cautionary Tale [NaNoRenO 18], OP Dodge Cross [GGJ 18], Acetone [AceJam 18]
Projects: I'm a love interest in my childhood friend's reverse harem!!
Organization: Watercress
itch: Drazillion
Contact:

Re: how to make a random choice against 2

#8 Post by Draziya »

Use [ code][/code] (without spaces) to show code with indents intact.

if randchara == m: and if randchara == s: should be if randchara == 'm': and if randchara == 's', because they're strings not the name of variables.
Image

User avatar
DragonKnight
Regular
Posts: 51
Joined: Sun Nov 12, 2017 10:16 am
Projects: Taboo Hearts
Contact:

Re: how to make a random choice against 2

#9 Post by DragonKnight »

Thank you!!!!!!!!!!!!!!!!!!!! I should have known that!!!
Currently working on Taboo Hearts :D
Currently working on Forbidden :D

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: how to make a random choice against 2

#10 Post by irredeemable »

When you do

Code: Select all

$ randchara = renpy.random.choice(['m', 's'])
The variable randchara is set to either the string 'm' or the string 's'. The if statement has to test for that string. If you don't put quotes around the m or s then Python will assume that you are referencing a variable named m or s. For example:

Code: Select all

label start:
    $ foo = "bar"
    if foo == "bar":
        "This is true."
    if foo == bar:
        "You won't see this because your game will crash."

Post Reply

Who is online

Users browsing this forum: Google [Bot], UltraRik