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.
-
Saltome
- Veteran
- Posts: 237
- Joined: Sun Oct 26, 2014 1:07 pm
- Deviantart: saltome
-
Contact:
#1
Post
by Saltome » Mon Nov 03, 2014 8:08 am
So I did some reading on the problem and it seems that this is normal behavior. But it's a bit of a hassle to use $ on every statement that has Python code, additionally that prevents me from being able to define functions which take control like the example I am giving. Granted functions may not even be the intended approach, and if it's not I'd like to learn the right one, but I was wondering if there isn't a way to instruct Ren'py that you do indeed want it to preserve of the state of the game during a Python block?
Code: Select all
def fight(a,b):
while a.hp>0 and b.hp>0:
if a.dexterity*renpy.random.random() > b.agility*renpy.random.random():
damage=(a.strength*renpy.random.random()-b.endurance*renpy.random.random())
b.hp-= max([damage,0]) #if damage > 0 else 0
renpy.say("", "Hit! (%F)" %b.hp)
else:
renpy.say("", "Miss!")
Deviant Art: 
-
nyaatrap
- Crawling Chaos
- Posts: 1824
- Joined: Mon Feb 13, 2012 5:37 am
- Location: Kimashi Tower, Japan
-
Contact:
#2
Post
by nyaatrap » Mon Nov 03, 2014 8:17 am
I think there's no way.
It's a bad idea to use while loop inside of python function. You need to wrap functions in ren'py's while loop:
Code: Select all
label something:
while True:
python:
fight(a,b)
-
Saltome
- Veteran
- Posts: 237
- Joined: Sun Oct 26, 2014 1:07 pm
- Deviantart: saltome
-
Contact:
#3
Post
by Saltome » Mon Nov 03, 2014 8:33 am
Well I like segmenting my code, I also like loops. So most of the code will have to be Ren'py, but Ren'py doesn't really have functions, so I guess my option there would be to utilize the call label as a replacement to python functions. I just feel a bit reluctant using labels since no tutorials I've seen really go into the details about labels, how to use them and how do they measure up to the alternative solutions.
Deviant Art: 
-
nyaatrap
- Crawling Chaos
- Posts: 1824
- Joined: Mon Feb 13, 2012 5:37 am
- Location: Kimashi Tower, Japan
-
Contact:
#4
Post
by nyaatrap » Mon Nov 03, 2014 8:40 am
What I'm doing is like:
Code: Select all
label main:
call loop_label(*args)
if _return is somehting:
etc
label loop_label(*args):
while True:
python:
functions
if condition:
return x
I could't have a better way than the above.
It's a pain that ren'py doesn't have for loop and break statement. I also need to use ren'py's loops instead of python's, but there are little options.
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#5
Post
by xela » Mon Nov 03, 2014 10:07 am
I am not sure if is even possible to try and preserve every state python is capable of and that definitely doesn't sound sensible. It is likely that you can code your own system for your own needs and merge that with rollback or otherwise extend the rollback system to your code but Nyaa's way is a lot better.
Like what we're doing? Support us at:

-
fluxus
- Regular
- Posts: 133
- Joined: Thu Jun 19, 2014 8:06 am
- Projects: Animal Anaesthesia (a teaching game)
-
Contact:
#6
Post
by fluxus » Thu Nov 06, 2014 4:19 am
There is a Ren'Py class to inherit from that's supposed to store the game state - couldn't you put functions and whatever oft-used python code is necessary onto such an object and preserve rollback that way?
Admittedly I don't know what I'm talking about as I'm not using rollback in my current project.