random chapter selection

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.
Post Reply
Message
Author
leequanhu
Newbie
Posts: 2
Joined: Fri Nov 09, 2018 3:35 am
Contact:

random chapter selection

#1 Post by leequanhu »

Hi,guys:
I want make a random chapter selection function for my game.After my test,random selection and text is ok,but when i add jump function,it fails.
jump function is ok in any other functions,can anybody tell me how to fix this.

screen if_test():
$ randchar = renpy.random.choice([1,2,3])
if (randchar==1) :
text _("result = 1")
jump "add1"
elif (randchar==2) :
text _("result = 2")
jump "add2"
else:
text _("result = 3")
jump "add3"

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: random chapter selection

#2 Post by Remix »

jump (as a lexer keyword) is only valid in labels

in screens, use

$ renpy.jump( "add1" )
Frameworks & Scriptlets:

leequanhu
Newbie
Posts: 2
Joined: Fri Nov 09, 2018 3:35 am
Contact:

Re: random chapter selection

#3 Post by leequanhu »

still not working,

report:
exception ui.interact called with non -empty widget /layer stacks.



screen if_test():
$ randchar = renpy.random.choice([1,2])
if (randchar==1) :
text _("result = 1")
$ renpy.jump( "add1" )
else:
text _("result ≥ 1")
$ renpy.jump( "add2" )
call screen if_test()

label add1:
e "add1 testing"
label add2:
e "add2 testing"

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: random chapter selection

#4 Post by Imperf3kt »

Try Jump - with a capital J

Code: Select all

screen if_test():
    $ randchar = renpy.random.choice([1,2,3])
    if (randchar==1) :
        text _("result = 1")
        Jump "add1"
    elif (randchar==2) :
        text _("result = 2")
        Jump "add2"
    else:
        text _("result = 3")
        Jump "add3"
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

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Why screen?

#5 Post by IrinaLazareva »

Code: Select all

label start:
    'Begin'

label chse:
    jump expression renpy.random.choice(['ad1', 'ad2', 'ad3'])

label ad1:
    "result = 1"
    return
label ad2:
    "result = 2"
    return
label ad3:
    "result = 3"
    return
https://www.renpy.org/doc/html/label.ht ... -statement
https://www.renpy.org/doc/html/other.html#renpy-random

Post Reply

Who is online

Users browsing this forum: Google [Bot]