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.
-
eoloe
- Newbie
- Posts: 1
- Joined: Wed Feb 24, 2010 11:02 pm
-
Contact:
#1
Post
by eoloe » Tue Mar 02, 2010 12:15 am
Hello !
I'm trying to jump or call labels at random.
let's say I have a list like this :
Code: Select all
list = ["forest", "town", "mountain", "swamp", "sea"]
I would like to be able to do a
Code: Select all
$ surprise = renpy.random.choice(list)
And then I would like to be able to something like this
or like this
Of course the two last lines are not working. Can you please help me to figure this out ?
Thank you
-
Asphodel
- Regular
- Posts: 28
- Joined: Sat Jan 17, 2009 1:40 am
-
Contact:
#2
Post
by Asphodel » Tue Mar 02, 2010 12:34 am
Try something like this:
In your init block, put:
and then in the main script where you want it to happen:
Code: Select all
$ surprise = int(random()*5) # There are 5 choices.
if surprise == 0:
jump forest
elif surprise == 1:
jump town
elif surprise == 2:
jump mountain
elif surprise == 3:
jump swamp
elif surprise == 4: # We end at N-1 because we started at zero.
jump sea
If you prefer counting from 1 to N instead of 0 to N-1, then you can instead write:
Code: Select all
$ surprise = int(random()*5+1)
if surprise == 1:
jump forest
and so forth.
Good luck!
-
denzil
- Veteran
- Posts: 293
- Joined: Wed Apr 20, 2005 4:01 pm
-
Contact:
#3
Post
by denzil » Tue Mar 02, 2010 1:35 am
eoloe wrote:And then I would like to be able to something like this
I believe what you actually want is: