Working with Python code in Ren'Py
Posted: Sun Dec 22, 2013 4:27 pm
I've been writing some (very) heavy python code over the last few days. And it's so complicated i only barely understand what i've written
. I've been writing it in python from the start rather than Ren'Py even if i've intended it for Ren'Py from the start simply because i'm pretty familiar with Python already, but i'm a total noob on Ren'Py and often take a while to figure out why Ren'Py rejects my code when it does.
Not long from now i am going to implement this code into a Ren'Py game (for prototyping purposes in this case) and i was wondering how best to do that. My code consists mostly of classes, it's only got one global variable in it (which is a short tuple). It's also only got one function. Everything else is a class usually linked together in a chain eventually leading to one class which will be used as a variable.
Short Example:
I figured i'll want to use an "init python:" block for this but is there any guide or tutorial for how to mix together Ren'Py and Python code and work with them together?
The only thing i know is "init python:" blocks and "$ variables = ..."
Is that really all there is to know? I'd like a few pointers, is there anything i should be wary of? should i keep an eye out for code i could implement as part of the Ren'Py code instead of being part of a Python block?
I've seen some code by others that does rely reasonably heavily on direct python scripts, but sometimes i see very python~y things like try/except and loops in the Ren'Py code. Overall i'm just pretty confused
Any pointers are appreciated, and i don't mind doing a bit of reading so if there is some good guide or documentation on this i should read then please link it.
Not long from now i am going to implement this code into a Ren'Py game (for prototyping purposes in this case) and i was wondering how best to do that. My code consists mostly of classes, it's only got one global variable in it (which is a short tuple). It's also only got one function. Everything else is a class usually linked together in a chain eventually leading to one class which will be used as a variable.
Short Example:
Code: Select all
class class1():
...
class class2(class1): #Class2 picks up Class1 and continues it
variable5 = 50
...
class class3(class2): #Class3 picks up Class2 and Class1 and continues them
...
class class4(class3): #Class4 picks up Class3, Class2 and Class1 and ends the chain of classes.
...
finalvar = class4()
finalvar.variable5 = 90
The only thing i know is "init python:" blocks and "$ variables = ..."
Is that really all there is to know? I'd like a few pointers, is there anything i should be wary of? should i keep an eye out for code i could implement as part of the Ren'Py code instead of being part of a Python block?
I've seen some code by others that does rely reasonably heavily on direct python scripts, but sometimes i see very python~y things like try/except and loops in the Ren'Py code. Overall i'm just pretty confused
Any pointers are appreciated, and i don't mind doing a bit of reading so if there is some good guide or documentation on this i should read then please link it.