Jumping to another script? [Solved]

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
User avatar
rjayne
Newbie
Posts: 15
Joined: Wed Feb 25, 2015 7:48 am
Contact:

Jumping to another script? [Solved]

#1 Post by rjayne »

Hi, Ren'py noob here. Sorry for the absurdly simple question, but I seem to be overlooking where the documentation makes reference to this.

I'd like to know how to jump to another script. In Python I would do:

Code: Select all

execfile("script_2.py") 
But Ren'Py is rejecting that. Likewise I've tried call call(""), action jump(") assuming it might work, but I'm a little at a loss about how it's done. Thanks.
Last edited by rjayne on Fri Mar 13, 2015 10:57 pm, edited 1 time in total.

User avatar
Mole-chan
Veteran
Posts: 333
Joined: Thu Aug 27, 2009 12:46 am
Completed: DUAEL, Escape from Puzzlegate
Projects: A Bird with Gold-Mended Wings
Deviantart: mole-chan
Skype: mole-chan
itch: moleworks
Contact:

Re: Jumping to another script?

#2 Post by Mole-chan »

Is there a particular reason you're using Python (.py) instead of Ren'py (.rpy)?
With the latter, you should just be able to jump to your desired label, regardless of what file it's in. Because Ren'py looks across all .rpy files.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Jumping to another script?

#3 Post by xela »

Ren'Py's main loop is structured to call labels one after another or logically from a stack. What you're asking for might not be doable at higher level. But within they script_2.py file you're bound to have a code structure that you can import and execute within a label just as your would within pure python environment, try:

Code: Select all

init:
    import script_2
# Delete all calls from the file and:

Code: Select all

label start:
    python:
        func1()
        class.method2()
        # etc
Like almost everything else, what you're trying to do might be possible with Ren'Py but it goes against it's concept and you're just creating problems for yourself in the future.
Like what we're doing? Support us at:
Image

User avatar
rjayne
Newbie
Posts: 15
Joined: Wed Feb 25, 2015 7:48 am
Contact:

Re: Jumping to another script?

#4 Post by rjayne »

Hi, thanks for the reply Mole Chan. I've changed to rpy, and tried both an init python block with execfile as well as:

Code: Select all

jump ("script_2.rpy")
and I get the following error:

Code: Select all

File "game/script.rpy", line 347: expected 'name' not found.
    jump ("script_2.rpy")
Xela, Does that mean I can't link to other scripts, and have to compile everything within a single script?
Last edited by rjayne on Fri Mar 13, 2015 9:10 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Jumping to another script?

#5 Post by xela »

rjayne wrote:Xela, Does that mean I can't link to other scripts, and have to compile everything within a single script?
Both yes and no.

You should compile everything as a single script, it's how Ren'Py is built by default (renpy.store or just store is where all globals get referenced to). Many of my friends rejected it for that reason but I personally love the implementation.

"no" part is this:

http://www.renpy.org/doc/html/python.ht ... med-stores

You can execute code outside of general "global" scope. I would never suggest this unless you're porting something really advanced from non Ren'Py environment with a lot of namespace collisions. If you're writing a game from scratch, stick to Ren'Py paradigm if you're using the engine. It will not steer you wrong.
Like what we're doing? Support us at:
Image

User avatar
rjayne
Newbie
Posts: 15
Joined: Wed Feb 25, 2015 7:48 am
Contact:

Re: Jumping to another script?

#6 Post by rjayne »

Okay, it's just very messy, and considering that the tutorial it comes bundled with is separated over seperate scripts, I assumed it was easy to link/jump between scripts. For a very long game, keeping everything in one script seems a bit silly.

User avatar
Mole-chan
Veteran
Posts: 333
Joined: Thu Aug 27, 2009 12:46 am
Completed: DUAEL, Escape from Puzzlegate
Projects: A Bird with Gold-Mended Wings
Deviantart: mole-chan
Skype: mole-chan
itch: moleworks
Contact:

Re: Jumping to another script?

#7 Post by Mole-chan »

The method I suggested requires you to jump to a specific label, not the script as a whole. For example:

Code: Select all

Jump(example)
With a label looking something like this

Code: Select all

label example:
    e "Hello!"
Treating it this way is why the tutorial can jump back and forth between scripts so easily.

If you'd rather treat your script as python code without the use of labels, I would advise listening to Xela instead. I can't claim to know the grand scheme of what you're attempting. I just know how it would be treated in a standard Ren'py game. ^^;

User avatar
rjayne
Newbie
Posts: 15
Joined: Wed Feb 25, 2015 7:48 am
Contact:

Re: Jumping to another script?

#8 Post by rjayne »

No problem, I think I was overcomplicating some of what I wanted to do, I'll figure out how to get it working in Ren'Py as the program intends :D

Thanks

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Jumping to another script?

#9 Post by xela »

rjayne wrote:Okay, it's just very messy, and considering that the tutorial it comes bundled with is separated over seperate scripts, I assumed it was easy to link/jump between scripts. For a very long game, keeping everything in one script seems a bit silly.
Labels serve as logical separator in Ren'Py. I am developing a game with over 50 000 lines of Python, Ren'Py script(s) and JSON/XML scripts. I never had any problems.

Ren'Py will compile all .rpy file as one singe file. All .py files you'll have to import (obviously just once during init). Labels are the real separators, .rpy files will all be loaded in a succession based in alphabetical/numerical succession. 00 are usually internal files.

Code: Select all

label start:
   # script
is the start point of the game. I initialize almost 3000 character, items, traits, buildings, maps and etc. in this label and then jump to the the real start of the game. You can jump from label to label, it doesn't matter if the label you jump to was defined in an earlier file because the game would have compiled all off the labels when the application was started. calling a label creates a stack, which means return will fall back to previous point of the stacked labels instead of terminating the game (which happens if you use only jumps).

It's very easy and beyond convenient to work with. I coded within python environment and in my own opinion, Ren'Py paradigm is a lot more pleasant. It just takes a bit of getting used to if you're coming from elsewhere
Like what we're doing? Support us at:
Image

User avatar
rjayne
Newbie
Posts: 15
Joined: Wed Feb 25, 2015 7:48 am
Contact:

Re: Jumping to another script?

#10 Post by rjayne »

Fair enough, thanks for the expanded explantion Xela. I'll mark this as solved.

User avatar
Steffenator
Regular
Posts: 53
Joined: Fri Feb 17, 2017 11:58 am
Contact:

Re: Jumping to another script? [Solved]

#11 Post by Steffenator »

You may or may not have ever played any of the Date Areane games (https://arianeb.wordpress.com/), but her actual script.rpy files are very small, and usually only handle the beginning and very end of her games. Pretty much everything in the middle is done with a bunch of separate rpy files, especially her Something's in the Air game. It splits off into a number of characters, each having their own rpy file.
Very organized.

I'm actually trying to do the same thing, link to different files, but its giving me fits. I'll get it.
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.


User avatar
MilywayObree
Newbie
Posts: 17
Joined: Sun Jan 28, 2018 11:24 am
Completed: None so far, pending to be exact
Projects: DDLC, The notebook and other secret projects
Organization: Vocastin/Oriaa Pro-Creations
Deviantart: MexicoRPelino
Github: HizashiroTakahashi
Skype: PixelMINEGaming
Location: Philippines
Contact:

Re: Jumping to another script? [Solved]

#12 Post by MilywayObree »

Ok, I know you already marked it solved and this post was from 3 years ago, well, I want to answer this question and I have the solution, the answer is just easy, I have been experimenting to get the same outcome as of what you would want too, and I buzzed out of tears and laughter when I was too dumb to know that it was just how easy it is, you know, to do it, you have to put the 2 scripts in the same destination/folder, for example.... "script1" and "script2", they must be in the same folder or place, for example I will put them in the same place, in my folder named "main_scripts", now then in the second script -- "script2", put a label, for example "label connect-branch:" and put whatever you want, and in the first script -- "script1" put, "jump (label name)" ---- in this case I will put "jump connect-branch", now launch your project, and VOILLA!! hope this post heleped you and I hope you are still alive lol! :lol: If it doesn't work, well it worked for me, maybe give up then :cry: , now I'm out! BYE!
Just Monika.

Post Reply

Who is online

Users browsing this forum: No registered users