Rock Paper Scissors?

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
Hakura0
Newbie
Posts: 18
Joined: Fri Jul 21, 2006 8:38 am
Contact:

Rock Paper Scissors?

#1 Post by Hakura0 »

Hi, I'm fairly new to Ren'Py, though it's not my first time looking into the program. At the moment I'm more or less experimenting at the moment, so I fugred I'd try to see if I could make a simple Rock paper scissors game for my little brother.

I read through some threads and the tutorials on the main page a bit, and I've got it working.

I've set it up so that it keeps track of the wins, losses and draws, easter eggs and certain counts of the score, etc.

This is the code I'm using:
"Rock":
if wins < max(losses, draws):
$ wins += 1
show scissors at right

c "Rock beats scissors..."
jump yc

elif wins > max(losses, draws):
$ draws += 1
show rock at right

c "Rock and Rock.. Draw."
jump yc


else:
$ losses += 1
show paper at right

c "Paper covers Rock YES!!"
jump yc

"Paper":
if draws < max(losses, wins):
$ wins += 1
show rock at right

c "Paper covers rock..."
jump yc

elif draws > max(losses, wins):
$ draws += 1
show paper at right

c "Paper and paper, draw."
jump yc

else:
$ losses += 1
show scissors at right

c "Scissors cut paper!"
jump yc

"Scissors":
if losses > max(wins, draws):
$ wins += 1
show paper at right

c "Scissors cut paper, drat."
jump yc

elif losses < max(wins, draws):
$ draws += 1
show scissors at right

c "Scissors and scissors...draw."
jump yc

else:
$ losses += 1
show rock at right

c "Rock beats scissors!"
jump yc
My question is if there's a better code I could use, or if this is pretty much it.

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Rock Paper Scissors?

#2 Post by monele »

So basically, this game automatically balances your wins and losses? ô_o...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Rock Paper Scissors?

#3 Post by JQuartz »

I don't think it's such a good idea to let the amount of wins, losses and draws to determine the outcome of a match. Maybe you should use renpy.random.randint(1, 3) instead. The following code might help you to get the idea (might have some mistakes in there so don't just copy and paste)

Code: Select all

# return a random integer between 1 and 3 with 1 as rock, 2 as scissors, 3 as cloth 
$ handsign = renpy.random.randint(1, 3)

rock:
  if handsign == 1:
  jump draw
  elif handsign == 2:
  jump win
  else: 
  jump loss
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Guest

Re: Rock Paper Scissors?

#4 Post by Guest »

Thanks, I think that's exactly what I needed. I wasn't sure if there was a way to have it randomize a number, and that was all I could think of.

Hakura0
Newbie
Posts: 18
Joined: Fri Jul 21, 2006 8:38 am
Contact:

Re: Rock Paper Scissors?

#5 Post by Hakura0 »

Ok, I tried it, looked the code up a few other places, but whatever I do I end up with
AttributeError: 'NoneType' object has no attribute 'random'
What am I doing wrong?

Chisakura
Newbie
Posts: 13
Joined: Mon May 28, 2007 3:23 pm
Location: Sweden, but finnish at heart. :)
Contact:

Re: Rock Paper Scissors?

#6 Post by Chisakura »

Hakura0 wrote:Ok, I tried it, looked the code up a few other places, but whatever I do I end up with
AttributeError: 'NoneType' object has no attribute 'random'
What am I doing wrong?
I'm not sure either... I had that same problem, but I got you a script finished, without the problem. :shock: I hope you have use of it. :oops: It works for me, I guess! xD

EDIT: I haven't added any pictures, texts telling what is happening ("Scissors cut paper" etc.) or easter eggs, so that'll be your homework! ;P
Attachments
script.rpy
Rock, Paper, Scissors script. Copy it in your game folder. But watch out that none of your games get replaced, make back-ups! O__O Always.
(1.92 KiB) Downloaded 106 times

Hakura0
Newbie
Posts: 18
Joined: Fri Jul 21, 2006 8:38 am
Contact:

Re: Rock Paper Scissors?

#7 Post by Hakura0 »

Thanks a bunch. I umm...*cough* found the problem. I wasn't putting the line in the right place. So luckily I didn't need to transplant everything, just re-write a few lines.

So I'll simplify this message: The script file was very helpful.

Chisakura
Newbie
Posts: 13
Joined: Mon May 28, 2007 3:23 pm
Location: Sweden, but finnish at heart. :)
Contact:

Re: Rock Paper Scissors?

#8 Post by Chisakura »

Hakura0 wrote:Thanks a bunch. I umm...*cough* found the problem. I wasn't putting the line in the right place. So luckily I didn't need to transplant everything, just re-write a few lines.

So I'll simplify this message: The script file was very helpful.
Well, that's great! That must have been the problem with my test too. xD

PS. I hope your little brother enjoys your game! :D Because my little brother doesn't even want to look at my games... ^^;
Wahwahwah! :twisted: Everyone everybody! Make some ice cream~!

User avatar
stwkun
Regular
Posts: 82
Joined: Wed Jan 02, 2013 7:57 pm
Organization: Stw Projects
Contact:

Re: Rock Paper Scissors?

#9 Post by stwkun »

Great job Chisakura, thanks :)

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]