[Solved]Randomizing events within the game without reloading
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.
[Solved]Randomizing events within the game without reloading
Something I am thinking of implementing into a future game is a calendar system, where there would be 30 days and within each individual day, there would be set events that always happen, and then randomized events that are different each time.
Is this possible, and if so, how would that look?
Thanks,
Cinto
Is this possible, and if so, how would that look?
Thanks,
Cinto
Last edited by Cinto on Sun May 05, 2013 10:13 pm, edited 1 time in total.
-
pwisaguacate
- Veteran
- Posts: 356
- Joined: Mon Mar 11, 2013 11:03 pm
- Contact:
Re: Randomizing events within the game without reloading
Fellow brothers and sisters, I am truly surprised to have come upon outdated manuscript that brought awe to the eyes. I crawled out of a dilapidated crypt and ran for the life of me that I must babble like a child and spread word across town. The text came from a document labeled "Category: Changed in 6.9.0":
I clumsily entered the random() into one of my sandbox scripts. I then scrawled "%(testnum)f seconds to glory" and ran the project. In anticipation, I began to laugh in faux evil...
Lo and behold, it works! It printed "0.432812 seconds to glory". I hit Start Game in the menu again: it printed ".647788 seconds to glory". My mind burned afire.
I recall hearing a brother mention pseudo-probability or something of the sorts, "though it's not completely random". But with this rediscovered technology, we may set an if statement to jump to certain labels dependent on the random numbers received!
EDIT: With a wide, sinister grin I devised a minigame:
Code: Select all
# return a random float between 0 and 1
$ randfloat = renpy.random.random()
# return a random integer between 1 and 20
$ d20roll = renpy.random.randint(1, 20)
# return a random element from a list
$ randfruit = renpy.random.choice(['apple', 'orange', 'plum'])
Lo and behold, it works! It printed "0.432812 seconds to glory". I hit Start Game in the menu again: it printed ".647788 seconds to glory". My mind burned afire.
I recall hearing a brother mention pseudo-probability or something of the sorts, "though it's not completely random". But with this rediscovered technology, we may set an if statement to jump to certain labels dependent on the random numbers received!
EDIT: With a wide, sinister grin I devised a minigame:
Code: Select all
label start:
$ survived = 0
label roulette:
$ test = renpy.random.randint(1,7)
d "Well, well..."
d "Play some Russian Roulette. You have a 1:7 chance to live."
if test != 1:
"BANG! You die."
$ survived = 0
else:
"You live!"
$ survived += 1
if survived == 10:
d "You survived 10 times! I'll let you leave the underworld... *snicker*"
return
else:
jump roulette
Last edited by pwisaguacate on Sun May 05, 2013 5:20 am, edited 6 times in total.
Re: Randomizing events within the game without reloading
Wow. Thanks. I think I get it.
One more thing, how would I make it so that certain events only activate after a prior random event has activated?
One more thing, how would I make it so that certain events only activate after a prior random event has activated?
-
pwisaguacate
- Veteran
- Posts: 356
- Joined: Mon Mar 11, 2013 11:03 pm
- Contact:
Re: Randomizing events within the game without reloading
It should work something like this (not tested):
Code: Select all
label start:
$ roulette = False
$ survived = 0
[random chance to initiate label roulette]
label roulette:
[...]
if survived == 10:
$ roulette = True
d "You survived 10 times! I'll let you leave the underworld... *snicker*"
jump leave
[...]
label other_scene:
if roulette == True
e "Wow, you are the first person to meet and survive Death!"
e "According to the legend, the others are forced to play for eternity..."
e "Lemmasoft heartily welcomes you back."
[...]
else:
pass