Hello!
I would like some help on randomizing scenes in a game of mine. Basically, I might have 5 scenes, a-e, and like at certain points in the story I want to just throw out these scenes, sort of like random events. Does that make sense? But I'm not sure how to go about with that.
Randomize Scenes
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.
- Head_Phones
- Regular
- Posts: 65
- Joined: Sun Oct 27, 2013 11:02 am
- Projects: Clichéd
- Location: Singapore
- Contact:
Randomize Scenes
'You may be a cunning linguist, but I am a master debater'
~Austin Powers
Profile pic drawn by the wonderful akemicchi
|| Honest Critique ||
~Austin Powers
Profile pic drawn by the wonderful akemicchi
|| Honest Critique ||
- Milkymalk
- Miko-Class Veteran
- Posts: 762
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: Randomize Scenes
You could check a random value after every scene and if it's a hit (say, a 0 when it's a random value from 0 to 19 for a 5% chance), you call a random label:
Insert that code whenever there's a chance that a random event could occur. Better yet, put it in a label block by itself and call it instead. Then in the event, use the return statement to return to the normal game flow.
If you want each event to only be called once ever, you have to do this instead (you have to declare the "uncalled" variables as True first or you will get an error, best to do this is in an init block):
There are more elegant ways to do this, but the basic principle should be clear.
Beware, I'm writing this from my head and there MIGHT be errors. Especially with the use of the int() function.
Code: Select all
$ check = int(20*renpy.random.random()) # creates a random number between 0 and 19
if check == 0:
$ destination = int(5*rempy.random.random()) # creates a random number between 0 and 4
if destination == 0:
call random_event_0
elif destination == 1:
call random_event_1
elif destination == 2:
call random_event_2
elif destination == 3:
call random_event_3
elif destination == 4:
call random_event_4
If you want each event to only be called once ever, you have to do this instead (you have to declare the "uncalled" variables as True first or you will get an error, best to do this is in an init block):
Code: Select all
if destination == 0 and event_0_uncalled:
$ event_0_uncalled = False
call random_event_0
elif destination == 1 and event_0_uncalled:
# etc.
Beware, I'm writing this from my head and there MIGHT be errors. Especially with the use of the int() function.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
- Head_Phones
- Regular
- Posts: 65
- Joined: Sun Oct 27, 2013 11:02 am
- Projects: Clichéd
- Location: Singapore
- Contact:
Re: Randomize Scenes
thank you so much for your help!
I'm very sorry but I don't quite understand the bottom portion.
So say I have ten questions and a couple have been used but I don't want the questions to repeat how would I go about doing that?
I'm very sorry but I don't quite understand the bottom portion.
So say I have ten questions and a couple have been used but I don't want the questions to repeat how would I go about doing that?
'You may be a cunning linguist, but I am a master debater'
~Austin Powers
Profile pic drawn by the wonderful akemicchi
|| Honest Critique ||
~Austin Powers
Profile pic drawn by the wonderful akemicchi
|| Honest Critique ||
- Milkymalk
- Miko-Class Veteran
- Posts: 762
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: Randomize Scenes
I don't understand what you mean by "questions".
The bottom portion checks a variable whenever a random scene is to be played. The variable stores if the scene has been played yet. If the scene has been played already, don't play it again. If it has not been played yet, change the variable and play the scene.
The problem with this method (that I just remembered) is that the more random scenes have been played, the chance to get a random scene at all becomes smaller.
Another possibility that'sprobably better:
Make a python list:
Put this somewhere inside your script:
When you want to check if a random scene should be played, you can just:
25 here is the probability in % that a random scene from the list will be played. You can change this number to whatever you like. 100 means a scene will be played no matter what.
This is all written from memory, if there are errors please ask me again.
The bottom portion checks a variable whenever a random scene is to be played. The variable stores if the scene has been played yet. If the scene has been played already, don't play it again. If it has not been played yet, change the variable and play the scene.
The problem with this method (that I just remembered) is that the more random scenes have been played, the chance to get a random scene at all becomes smaller.
Another possibility that's
Make a python list:
Code: Select all
init python:
nrs = 10 # number of random scenes
random_scenes = range(nrs) # creates a list containing the numbers 0 to (nrs minus 1)
Code: Select all
label play_random_scene(prob):
python:
pick = -1 # so that, after the list is empty, the last scene won't be played over and over
if len(random_scenes) > 0: # make sure there are scenes left before picking
check = int(100*renpy.random.random()) # creates a random number between 0 and 99
if check < prob: # if the number is low enough, play a random scene! (prob)% chance
pick = random_scenes[renpy.random.random()*len(random_scenes)] # pick a random one from the list
del random_scenes[pick] # delete the picked number from the list so it will not get picked again
if pick == 0:
call random_event_0 # adjust these to your own label names
elif pick == 1:
call random_event_1
# and so on
return
Code: Select all
call play_random_scene(25)
This is all written from memory, if there are errors please ask me again.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Who is online
Users browsing this forum: No registered users