how to make a random choice against 2
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.
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.
- DragonKnight
- Regular
- Posts: 51
- Joined: Sun Nov 12, 2017 10:16 am
- Projects: Taboo Hearts
- Contact:
how to make a random choice against 2
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
Currently working on Forbidden
Currently working on Forbidden
-
- Regular
- Posts: 78
- Joined: Thu Feb 08, 2018 7:57 am
- Contact:
- 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
"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)
$ 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
Currently working on Forbidden
Currently working on Forbidden
-
- Regular
- Posts: 78
- Joined: Thu Feb 08, 2018 7:57 am
- Contact:
Re: how to make a random choice against 2
What exactly are you trying to do? For one thing you need to use indentation, so the last part should look like:
That's assuming you intended to simply display those strings in the dialogue box.
Code: Select all
if slept_alone:
$ randchara = renpy.random.choice(['m', 's'])
if randchara == 'm':
"Then m"
"Mom"
elif randchara == 's':
"Then s"
"Sis"
- 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
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
$ 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
Currently working on Forbidden
Currently working on Forbidden
-
- Regular
- Posts: 78
- Joined: Thu Feb 08, 2018 7:57 am
- Contact:
Re: how to make a random choice against 2
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.
- 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
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
Currently working on Forbidden
Currently working on Forbidden
- 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
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.
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.
- 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
Thank you!!!!!!!!!!!!!!!!!!!! I should have known that!!!
Currently working on Taboo Hearts
Currently working on Forbidden
Currently working on Forbidden
-
- Regular
- Posts: 78
- Joined: Thu Feb 08, 2018 7:57 am
- Contact:
Re: how to make a random choice against 2
When you do
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
$ randchara = renpy.random.choice(['m', 's'])
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."
Who is online
Users browsing this forum: No registered users