Rock-Paper-Scissors Problems

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
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Rock-Paper-Scissors Problems

#1 Post by zankizuna » Sun Jun 23, 2013 12:29 am

I've tried the codes you people taught me from a long time ago.
http://lemmasoft.renai.us/forums/viewto ... =8&t=19171

Problem 1:
I want to Randomize the Choice of the Foe(PC), so I used this:

Code: Select all

$ foecard = renpy.random.choice(['Rock', 'Paper', 'Scissors'])
but the error points out to this and says it's invalid or somethin' like that..

Problem 2:
ROCK vs SCISSOR= DRAW
The image below explains... Why is it like that?
I used what PyTom told me and followed through.. what's the matter?
Since the Foe's choice can't be randomized,
I defined the foe's choice by calling labels that looked like this:

Code: Select all

label foescissors:
  $ foecard = ["Scissors"] 
  show Scissors as fchoice at pos5 with moveinright
  return 
same went for Rock and Paper.
Player's choice was defined by an imagemap.
It linked to these:

Code: Select all

label Rock:
        $ playercard = ["Rock"]
        show Rock at pos3 with moveinleft
        jump next 
label Paper:
              
        $ playercard = ["Paper"]
        show Paper at pos1 with moveinleft
        jump next 
label Scissors:
        
        $ playercard = ["Scissors"]
        show Scissors at pos1 with moveinleft
        jump next  
 
After Choosing, This goes.. sadly, It seems to ignore if and elif and goes straight to else,
whatever option you pick.

Code: Select all

label next:    
    "Compare!"
# Foe's Card defined here by call: foe+("rock",paper,scissors)  
    call foescissors
    call check
    if rps_win(playercard, foecard):
     "Player wins, Foe lost."
    elif rps_win(foecard, playercard):
     "Foe Wins, You Lost."
    else:
     "Draw"
    ""
    
And this, label check, defines which pair would win.

Code: Select all

label check:  
 init python:

    # This contains the tuple (a, b) if a wins against b.
    RPS_WINS = [ ("Rock", "Scissors")or ("Scissors", "Paper")or ("Paper", "Rock") ]

    # Returs true if a beats be in Rock-paper-scissors.
    def rps_win(playercard, foecard):
        return (playercard, foecard) in RPS_WINS
 return
I have no problem with anything else except that It's always "Draw".
Attachments
screenshot0011.png

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Rock-Paper-Scissors Problems

#2 Post by OokamiKasumi » Sun Jun 23, 2013 2:39 am

zankizuna wrote:I've tried the codes you people taught me from a long time ago. ...
Darlin', coding questions belongs in the Renpy Questions and Announcements sub-forum. http://lemmasoft.renai.us/forums/viewforum.php?f=8
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
Taleweaver
Writing Maniac
Posts: 3428
Joined: Tue Nov 11, 2003 8:51 am
Completed: Metropolitan Blues, The Loyal Kinsman, Daemonophilia, The Dreaming, The Thirteenth Year, Adrift, Bionic Heart 2, Secrets of the Wolf, The Photographer
Projects: The Pilgrim's Path, Elspeth's Garden, Secret Adventure Game!
Organization: Tall Tales Productions
Location: Germany
Contact:

Re: Rock-Paper-Scissors Problems

#3 Post by Taleweaver » Sun Jun 23, 2013 3:15 am

Yup, they do.

Moving.
Scriptwriter and producer of Metropolitan Blues
Creator of The Loyal Kinsman
Scriptwriter and director of Daemonophilia
Scriptwriter and director of The Dreaming
Scriptwriter of Zenith Chronicles
Scriptwriter and director of The Thirteenth Year
Scriptwriter and director of Romance is Dead
Scriptwriter and producer of Adrift
More about me in my blog
"Adrift - Like Ever17, but without the Deus Ex Machina" - HigurashiKira

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Rock-Paper-Scissors Problems

#4 Post by kankan » Sun Jun 23, 2013 3:57 am

I can't replicate the first problem, but I do see the second one. You're setting playercard to a list containing the player choice instead of the choice itself. If you plug it in directly in a python shell, it turns out something like this:

Code: Select all

>>> playercard = ["Scissors"]
>>> foecard = "Rock"
>>> (foecard, playercard)        #this is the tuple you're making in your code
    ("Rock", ["Scissors"])
>>> ("Rock", ["Scissors"]) in RPS_WINS
    False
Try taking the brackets off when you're setting playercard under the rock, paper, and scissor labels!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]