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.
-
wjannsz
- Newbie
- Posts: 10
- Joined: Sat Jul 14, 2012 7:33 am
-
Contact:
#1
Post
by wjannsz » Sun May 10, 2015 11:46 am
Hi all,
I've been puzzled by how a random encounter could be scripted in games.
For example, say there's a secret travelling merchant that could be available at 12 locations.
My thinking at the moment is to use the random function to decide where the merchant would be on this day (beach), so if you don't choose to go to the beach, you won't see the merchant.
Another thought is: when the player goes to the park, a random function will decide whether the merchant will show (1/13 chance). If true, merchant will show up.
This thought came after playing FFIII, with the Legendary Smith.
I'm curious as to how these event logics are usually designed, please help?
Many thanks in advance

-
kitsalai
- Regular
- Posts: 65
- Joined: Wed Jan 08, 2014 11:05 pm
- Projects: Imaginatum
- Location: US
-
Contact:
#2
Post
by kitsalai » Sun May 10, 2015 2:21 pm
Both methods you mentioned will work fine. I believe most random encounters in modern games use psuedorandom generators as to make the player feel the sense of "randomness". You don't want to random hit a 10% chance two times in a row or never hit a 10% after 100 tries after all. For our purposes, renpy's random or python's random is suffice.
http://www.renpy.org/doc/html/other.html#renpy-random
As to whether when you want to generate that random location is up to you. Note that if you random the location of the merchant
before the player clicks the location, the player can save the game immediately beforehand and try up to 12 times to get it right. If you choose to generate the random encounter
after the player clicks, it will make it more difficult for the player to find the merchant by saving/loading.
The design is up to you, but in my opinion I prefer the player to feel at ease and would select the merchant beforehand.
-
Onishion
- Veteran
- Posts: 295
- Joined: Mon Apr 20, 2015 10:36 am
-
Contact:
#3
Post
by Onishion » Sun May 10, 2015 10:42 pm
Yeah, it might be nice to just schedule the merchant and let players learn the patter themselves. I tend to prefer rare but potentially predictable system to one that is truly random.
-
trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
-
Contact:
#4
Post
by trooper6 » Sun May 10, 2015 11:28 pm
Onishion wrote:Yeah, it might be nice to just schedule the merchant and let players learn the patter themselves. I tend to prefer rare but potentially predictable system to one that is truly random.
I also tend to prefer the "realistic" way...which is to give the merchant a schedule.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe:
http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
-
Onishion
- Veteran
- Posts: 295
- Joined: Mon Apr 20, 2015 10:36 am
-
Contact:
#5
Post
by Onishion » Mon May 11, 2015 12:18 am
Btw, is there some kind of "on rollback" trigger? If so, a fun little troll, without making rollback impossible, might be to make it so that the location is random, so in theory they could keep rolling back and retrying until the hit it right, but have a trigger so that if they do rollback at that time, it blocks the merchant out until the next "turn," whenever that is, so that even if they did get the right RNG roll for him to appear, he just wouldn't. It shouldn't cause any damage that they wouldn't already have if they were playing it fair.

-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#6
Post
by xela » Mon May 11, 2015 3:35 am
I think renpy.random "remembers" it's choices when rolling back. They would have to save/reload to get a new result. Otherwise, you can always lock the seed to use a separate function to make sure that even loading doesn't put your merchant in the new location. We discussed something like this in the cookbook long time ago.
Like what we're doing? Support us at:

-
wjannsz
- Newbie
- Posts: 10
- Joined: Sat Jul 14, 2012 7:33 am
-
Contact:
#7
Post
by wjannsz » Mon May 11, 2015 7:53 am
ah... I was thinking inside a tiny box. I didn't think about the good old save/load method at all, even though I did that all the time when I played games :p. not being able to S/L does take out a lot of the fun.
If the player saves right before the clicking the location and then the merchant-random event runs, it would be easier for player to S/L, while possibly loses the point of me making merchant appearances random. I'll have to bear in mind the effect of the rollback function as well. (too many rollbacks will unlock achievements sounds like fun.)
from my past usage of renpy.random.choice, I believe that the choice will be the same when rolling back and forth.
Thanks for all your opinions and input above, I think from what you guys have suggested, I'll be going for scripted randomness. That is, patterns that are discoverable to players that have followed the stories/hidden hints, while to a new player it would be completely random.
Mmmm......i'll go get my thinking cap!
-
morg
- Regular
- Posts: 95
- Joined: Sun May 10, 2015 7:35 am
- Projects: Cupid's Affair
- Tumblr: n-morg
-
Contact:
#8
Post
by morg » Mon May 11, 2015 10:30 am
there's one way to do that listed in the ren'py cookbook which i think you'll find very useful:
http://www.renpy.org/wiki/renpy/doc/coo ... han_others
i also have my own way i made up quickly..
Code: Select all
label start:
$ visited_beach = 0
$ visited_waterfall = 0
call screen imagemap #imagemap that has all the locations
label beach:
$ visited_beach += 1
if visited_beach <= 13:
"hm.. i can't find him here.."
jump start
else:
show merchant
"there you are!"
#continue the story...
label park:
#it is impossible to find him in the park
"he isn't here"
jump start
label waterfall:
$ visited_waterfall += 1
if visited_waterfall <= 10: #the chance of finding him in the waterfall is higher
"he ain't here."
jump start
else:
show merchant
"there u are"
#etc
and if you want to make the places the merchant can be random you could use the generator
Code: Select all
$ place = renpy.random.choice(["beach", "park", "waterfall"])
and then adding it like so:
Code: Select all
define m = Character("Merchant")
label start:
$ place = renpy.random.choice(["beach", "park", "waterfall"])
$ visited_beach = 0
$ visited_waterfall = 0
call screen imagemap #imagemap that has all the locations
label beach:
if place == "beach":
$ visited_beach += 1
if visited_beach <= 13:
"hm.. i can't find him here.."
jump start
else:
show merchant
"there you are!"
#continue the story...
else:
"he isn't here"
jump start
label park:
if place == "park":
$ visited_park += 1
if visited_park <= 13:
"not here"
jump start
else:
show merchant
m "i see you've found me"
"yeah. finally"
#continue story or jump to label
else:
"he isn't here"
jump start
label waterfall:
if place == "waterfall":
$ visited_waterfall += 1
if visited_waterfall <= 10: #the chance of finding him in the waterfall is higher if the get it
"he ain't here."
jump start
else:
show merchant
"there u are"
#continue story or jump to the next event label
else:
"not here"
jump start
ofcourse that's a ton of programming and may or may not suit you... and like what has been said the random generator can't be used how you want it because the result you get doesn't change until you restart, but it can be used to randomize events

-
wjannsz
- Newbie
- Posts: 10
- Joined: Sat Jul 14, 2012 7:33 am
-
Contact:
#9
Post
by wjannsz » Mon May 11, 2015 1:14 pm
hi morg,
thanks for directing me to that page and laying out a foundation for me.
i gave it a try and this is what i came up with.
Code: Select all
init python:
class NonUniformRandom(object):
def __init__(self, list_of_values_and_probabilities):
"""
expects a list of [ (value, probability), (value, probability),...]
"""
self.the_list = list_of_values_and_probabilities
self.the_sum = sum([ v[1] for v in list_of_values_and_probabilities])
def pick(self):
"""
return a random value taking into account the probabilities
"""
import random
r = random.uniform(0, self.the_sum)
s = 0.0
for k, w in self.the_list:
s += w
if r < s: return k
return k
define m = Character("Merchant")
label start:
$choose = renpy.input("Where do you want to go today? beach, park or waterfall?")
while choose != "beach" and choose != "park" and choose != "waterfall":
"I'm sorry, [choose] is not available for visiting yet, please choose again."
jump start
label places:
$ locations = [('beach',10),('park',3),('waterfall',5)]
$ place = NonUniformRandom(locations)
if place.pick() == choose:
"I see you've found me."
else:
"Nope, not here."
jump start
i think this might do what i want. i put the generator after the click, and tested. the result will still change after rollback
Users browsing this forum: Hojoo