rock paper scissors on renpy [solved]

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
ishify
Newbie
Posts: 23
Joined: Thu Aug 15, 2013 5:25 pm
IRC Nick: Ishy
Contact:

rock paper scissors on renpy [solved]

#1 Post by ishify »

I have found this code while searching about how to implement the game in renpy.

I am currently having trouble with the rps_beats bit because I don't really know what to do after declaring it, or what to put in it.

Code: Select all

label rps:

    menu:
        "Rock!":
            $ rps_player = "rock"
        "Paper!":
            $ rps_player = "paper"
        "Scissors!":
            $ rps_player = "scissors"
            
    $ rps_npc = renpy.random.choice(["rock", "paper", "scissors"])

    e "I choose %(rps_npc)s!"

    if (rps_player, rps_npc) in rps_beats:

        e "You beat me!"

    elif (rps_npc, rps_player) in rps_beats:

        e "I win!"

    else:

        e "It's a tie! Let's do it again!"
        jump rps

    # ...
Last edited by ishify on Sat Jan 17, 2015 3:54 pm, edited 1 time in total.
ImageI'm a bored potato so come talk to me pleaseImage

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

Re: rock paper scissors on renpy

#2 Post by philat »

Well, seems like it's just a matter of creating the list. Stick this anywhere before the if conditionals.

Code: Select all

$ rps_beats = [("rock", "scissors"), ("scissors", "paper"), ("paper", "rock")]

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: rock paper scissors on renpy

#3 Post by PyTom »

Since it doesn't actually change, I'd suggest placing this in a define.

Code: Select all

define rps_beats = [("rock", "scissors"), ("scissors", "paper"), ("paper", "rock")]
Actually, it's probably more stylistic to name a constant like this RPS_BEATS - the all-uppercase lets us know it's a constant that we should never change, and never expect to change. This doesn't change the behavior at all, but it lets people reading your code - including yourself in a few days, months, or years - know more about the variable.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
ishify
Newbie
Posts: 23
Joined: Thu Aug 15, 2013 5:25 pm
IRC Nick: Ishy
Contact:

Re: rock paper scissors on renpy

#4 Post by ishify »

Oh, so that's how it works.

Ah, yes, the tip would come in handy. Thank you.
ImageI'm a bored potato so come talk to me pleaseImage

Post Reply

Who is online

Users browsing this forum: No registered users