Page 1 of 1

Ren'py language vs standard python

Posted: Sat Nov 07, 2020 4:27 am
by bugsyy
Hi, I'm currently new to renpy so I just have few question about the diff between renpy language vs python:

1. is ""Init: python:"" equivalent to ""init python:"""
2. when creating a new python script and I want to use it in another script, do I have still have to use the "import" keyword?
3. Is it possible to use Ren'py code when defining a function in python? (or are there anyways to define a function in ren'py language)
4. What IDE do u guys usually use for ren'py and is it possible to use pycharm?
5. Recommended source to learn about the transform of stuff like xoffset/xposition/etc of an image or a screen stuff

Re: Ren'py language vs standard python

Posted: Sat Nov 07, 2020 6:17 am
by Imperf3kt
-Init python: doesn't work with Ren'Py, only init pyton:
-import is not necessary if you've added the code to another script file already (Unless you're trying to reference the code before it exists)
-renpy does have its own pythonic equivalents for many things, but you can generally just use standard python in your function unless there's a specific reason to use the renpy version
-I just use Editra as my IDE. It works, and was packaged with Ren'Py when I first downloaded it. It has since been updated to Atom in the official builds, but I still prefer Editra and still use it.
- the documentation is always the most accurate, but not necessarily the best to learn from. ren'Py has a discord that may help as well.
https://www.renpy.org/doc/html/

Re: Ren'py language vs standard python

Posted: Sat Nov 07, 2020 7:12 am
by bugsyy
So is"""
init python:
code
the same as
init:
python:
code
"""
sorry if my question wasn't clear ( what i meant was is init python the same as init: that takes in a python code block)
And do i need to have any reference code to an another rpy scripts or i don't need it ( such as I can just jump to a label that is in another script)
Also, are there any good coding tips on how things should be organized?

Re: Ren'py language vs standard python

Posted: Tue Nov 24, 2020 2:15 am
by gas
Yes, they are equivalent.

Code: Select all

init python:
    # your codelines
is equal to say:

Code: Select all

init:
    python:
        # your codeline
The obvious difference is that in the first case you told that ALL lines that follow in the block MUST BE python lines. In the second case you can do a mixed thing.

As for referencing.
The moment you launch a game, renpy first scan the whole scripts. Do the init stuff wherever they are, ignoring the rest. They can be splitted between 3000 scripts, if you want for.
MIND THAT also the statements "DEFAULT" and "DEFINE" (and to my knowledge, "TRANSFORM") are registered at this point in time and can be put wherever you want.
Renpy execute the "init" things at any arbitrary order (mostly unpredictable). While this usually is not a problem, sometime you want to have the init define first something that you must use later in other init steps.
For this reason, you can use
init -x:
the lower the X the earlier the following block willbe executed in the init phase.

Code: Select all

init -10:
     # bla bla bla
init -20:
    # bla bla bla
The second block will be executed before the first.

THEN.
After this 'init' phase, it enter the main menu context. When you exitthe main menu context, it start from the "start" label where it can find it (as for default, you can state differently, but let's begin easily: it go to the start label).
From now onward it proceed line by line. If the ACTUAL script end without jumping somewhere else, renpy cnsider the game ended.
At any point, if you JUMP/CALL another label, you can JUMP/CALL to any label doesn't matter the actual script he does find it.
No need to quote it in advance. Renpy is able to find that label between 10.000 scripts you gave.
Again, it proceed line by line fromthat point onward and if reach the end of that text file and no more lines are there, it consider the game ended.

How things should be organized?
That depend on the lenght of your game.
As common practice, if a given kind of entry occupy big space, you should create a different script.
So, for example, if your game own 3000 characters, probably is quite better to create a new script, name it the way you want, and include here so much definitions.
Mind the logic above: as long as they are 'init' stuff, renpy will find them. If you need a given order, use init -x.

The same goes for labels. If you have a core script that jump back and forth a lot of sublabels, probably is better to write them on other script files. Renpy will be able to JUMP/CALL to wherever they are.

NOTE: the execution ignore screens blocks. That's mean if you're crazy enough you can define screens in the middle of a narration and renpy will ignore the entire block. The same, screens can be defined in whatever and as many scripts you want.