Rock, Paper, Scissors in Ren'Py?
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.
-
- Eileen-Class Veteran
- Posts: 1314
- Joined: Mon Sep 19, 2005 2:15 am
- Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
- Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
- Organization: Watercolorheart Studios
- IRC Nick: BCS
- Tumblr: adminwatercolor
- Deviantart: itsmywatercolorheart
- Github: Watercolordevdev
- Skype: heartnotes
- Soundcloud: Watercollider
- itch: watercolorheart
- Location: Florida
- Contact:
Rock, Paper, Scissors in Ren'Py?
How would one go about using the random number generator to program a code for a little Rock, Paper, Scissors game without rigging it? (Random every time?)
- PyTom
- Ren'Py Creator
- Posts: 16088
- 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:
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
# ...
I should point out that rollback will make an RPS game easy to win, and there's not much to be done about that apart from disabling rollback. (Even if rollback was disabled/blocked, one could still save before the RPS event, and have a 1/2 chance of winning on each playthrough.)
In general, I question whether having random elements in a game is a good idea.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
-
- Eileen-Class Veteran
- Posts: 1314
- Joined: Mon Sep 19, 2005 2:15 am
- Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
- Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
- Organization: Watercolorheart Studios
- IRC Nick: BCS
- Tumblr: adminwatercolor
- Deviantart: itsmywatercolorheart
- Github: Watercolordevdev
- Skype: heartnotes
- Soundcloud: Watercollider
- itch: watercolorheart
- Location: Florida
- Contact:
The decision to "cheat" or not to "cheat" - well, the outcome of the rock, paper, scissors in a game may not always to win it ... but it may sometimes be, depending. Things aren't always as clear-cut as they seem ...
If you win, one thing may happen, and you may get a short-term reward for that ... but if you lose or tie, does something else happen later from that which could reveal something else?
Of course, I could just ask you how to temporarily disable rollback or saving at menus, but NOT disable for anytime a menu isn't displayed.
If you win, one thing may happen, and you may get a short-term reward for that ... but if you lose or tie, does something else happen later from that which could reveal something else?
Of course, I could just ask you how to temporarily disable rollback or saving at menus, but NOT disable for anytime a menu isn't displayed.
-
- Newbie
- Posts: 5
- Joined: Thu Feb 08, 2018 3:05 am
- Tumblr: uloacs.tumblr.com
- Contact:
Re: Rock, Paper, Scissors in Ren'Py?
I'm sorry, but how you define renpy_beats.
I mean i just copy the whole coding, but it turns out that renpy_beats is not defined yet. Can anyone solve this?
I mean i just copy the whole coding, but it turns out that renpy_beats is not defined yet. Can anyone solve this?
Code: Select all
I'm sorry, but an uncaught exception occurred. While running game code: File "game/script.rpy", line 27, in script if (rps_player, rps_npc) in rps_beats: File "game/script.rpy", line 27, in <module> if (rps_player, rps_npc) in rps_beats: NameError: name 'rps_beats' is not defined -- Full Traceback ------------------------------------------------------------ Full traceback: File "game/script.rpy", line 27, in script if (rps_player, rps_npc) in rps_beats: File "D:\Game\Renpy 6.99\renpy\ast.py", line 1681, in execute if renpy.python.py_eval(condition): File "D:\Game\Renpy 6.99\renpy\python.py", line 1794, in py_eval return py_eval_bytecode(code, globals, locals) File "D:\Game\Renpy 6.99\renpy\python.py", line 1788, in py_eval_bytecode return eval(bytecode, globals, locals) File "game/script.rpy", line 27, in <module> if (rps_player, rps_npc) in rps_beats: NameError: name 'rps_beats' is not defined Windows-8-6.2.9200 Ren'Py 6.99.13.2919 Zehaha 1.0
- SilverKnight99O, Somebody that tries to make games with friends.
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Rock, Paper, Scissors in Ren'Py?
Code: Select all
default rps_beats = [('rock', 'scissors'), ('scissors', 'paper'), ('paper', 'rock')]
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Rock, Paper, Scissors in Ren'Py?
I actually made my own RPS game a couple of months ago because I didn't like the already available options that much.
Here's a copy of the whole thing, if you prefer this. With this, the stats reset each time you start a new game:
And the related screens:
Remember to add a button to the menu that opens the "cheat" menu. example:
Here's a copy of the whole thing, if you prefer this. With this, the stats reset each time you start a new game:
Code: Select all
define d = Character("Developer")
default result = "none"
default selection = "none"
default score = 0
default computer = 0
default ties = 0
default persistent.cheating = 0
label start:
scene rps
# The above statement expects a file called rps (jpg or png) inside the images folder.
show screen stats
label rps_select:
if not persistent.cheating:
menu:
"Rock":
$selection = "rock"
$result = renpy.random.choice(['rock', 'paper', 'scissors'])
"Paper":
$selection = "paper"
$result = renpy.random.choice(['rock', 'paper', 'scissors'])
"Scissors":
$selection = "scissors"
$result = renpy.random.choice(['rock', 'paper', 'scissors'])
"End":
return
else:
menu:
"Rock":
$selection = "rock"
$result = "scissors"
"Paper":
$selection = "paper"
$result = "rock"
"Scissors":
$selection = "scissors"
$result = "paper"
"End":
return
label results:
####rock####
if result == "rock":
if selection == "rock":
jump tie
elif selection == "paper":
jump win
elif selection == "scissors":
jump lose
####paper####
elif result == "paper":
if selection == "rock":
jump lose
elif selection == "paper":
jump tie
elif selection == "scissors":
jump win
####scissors####
elif result == "scissors":
if selection == "rock":
jump win
elif selection == "paper":
jump lose
elif selection == "scissors":
jump tie
label tie:
d "We tied with [result]!"
$ ties += 1
jump rps_select
label win:
d "[selection] beats [result], you win!"
$ score += 1
jump rps_select
label lose:
d "[result] beats [selection], you lost!"
$ computer += 1
jump rps_select
Code: Select all
screen stats():
modal False
zorder 100
vbox:
xalign 0.5
ypos 0.01
text "{color=#000}Computer: [computer] You: [score] Ties: [ties]{/color}"
screen cheats():
tag menu
use game_menu(_("Cheats"), scroll="viewport"):
style_prefix "cheats"
hbox:
vbox:
label "Never Lose"
textbutton _("On") action SetField(persistent, "cheating", 1)
textbutton _("Off") action SetField(persistent, "cheating", 0)
style cheats_label is gui_label
style cheats_label_text is gui_label_text
style cheats_text is gui_text
style cheats_label_text:
size gui.label_text_size
Code: Select all
textbutton _("Cheats") action ShowMenu('cheats') alternate ShowMenu('cheats')
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- TsugumiLightning
- Newbie
- Posts: 23
- Joined: Sat Aug 11, 2018 5:28 am
- Organization: STAY
- Location: 🇦🇺
- Contact:
Re: Rock, Paper, Scissors in Ren'Py?
Thanks, this helped me a lot!Imperf3kt wrote: ↑Sun Apr 01, 2018 4:39 am I actually made my own RPS game a couple of months ago because I didn't like the already available options that much.
Here's a copy of the whole thing, if you prefer this. With this, the stats reset each time you start a new game:And the related screens:Code: Select all
define d = Character("Developer") default result = "none" default selection = "none" default score = 0 default computer = 0 default ties = 0 default persistent.cheating = 0 label start: scene rps # The above statement expects a file called rps (jpg or png) inside the images folder. show screen stats label rps_select: if not persistent.cheating: menu: "Rock": $selection = "rock" $result = renpy.random.choice(['rock', 'paper', 'scissors']) "Paper": $selection = "paper" $result = renpy.random.choice(['rock', 'paper', 'scissors']) "Scissors": $selection = "scissors" $result = renpy.random.choice(['rock', 'paper', 'scissors']) "End": return else: menu: "Rock": $selection = "rock" $result = "scissors" "Paper": $selection = "paper" $result = "rock" "Scissors": $selection = "scissors" $result = "paper" "End": return label results: ####rock#### if result == "rock": if selection == "rock": jump tie elif selection == "paper": jump win elif selection == "scissors": jump lose ####paper#### elif result == "paper": if selection == "rock": jump lose elif selection == "paper": jump tie elif selection == "scissors": jump win ####scissors#### elif result == "scissors": if selection == "rock": jump win elif selection == "paper": jump lose elif selection == "scissors": jump tie label tie: d "We tied with [result]!" $ ties += 1 jump rps_select label win: d "[selection] beats [result], you win!" $ score += 1 jump rps_select label lose: d "[result] beats [selection], you lost!" $ computer += 1 jump rps_select
Remember to add a button to the menu that opens the "cheat" menu. example:Code: Select all
screen stats(): modal False zorder 100 vbox: xalign 0.5 ypos 0.01 text "{color=#000}Computer: [computer] You: [score] Ties: [ties]{/color}" screen cheats(): tag menu use game_menu(_("Cheats"), scroll="viewport"): style_prefix "cheats" hbox: vbox: label "Never Lose" textbutton _("On") action SetField(persistent, "cheating", 1) textbutton _("Off") action SetField(persistent, "cheating", 0) style cheats_label is gui_label style cheats_label_text is gui_label_text style cheats_text is gui_text style cheats_label_text: size gui.label_text_size
Code: Select all
textbutton _("Cheats") action ShowMenu('cheats') alternate ShowMenu('cheats')
there are days where you cry for no reason, and today is not one of those days.
"Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference."
- Robert Frost, The Road Not Taken
"Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference."
- Robert Frost, The Road Not Taken
Who is online
Users browsing this forum: No registered users