Page 1 of 1

how to make a random choice against 2

Posted: Sun Feb 18, 2018 1:18 pm
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.

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 1:29 pm
by irredeemable

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 2:13 pm
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)

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 2:31 pm
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.

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 6:58 pm
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

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 7:05 pm
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.

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 7:11 pm
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??

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 7:15 pm
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.

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 7:23 pm
by DragonKnight
Thank you!!!!!!!!!!!!!!!!!!!! I should have known that!!!

Re: how to make a random choice against 2

Posted: Sun Feb 18, 2018 7:23 pm
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."