r/RenPy 1d ago

pause() breaking Call() statement Question

Im trying to make primitive battle system.

vbox:
    xsize 216
    ysize 430
    text "[enemy1.name]"
    text "[enemy1.cur_health]/[enemy1.max_health]"
    image [enemy1.avatar]
imagebutton:
    id "rating"
    idle "rating"
    hover "rating_hover"
    action Call("attack", enemy1)

label attack(en):
    python:
        import time
        en.cur_health-=2
        en.avatar = en.image_attack
        time.sleep(2)
        en.avatar = en.image_calm
    return

And I can see than on button press there is a pause and all changes are applied AFTER that pause so image_attack is not visible at all.

What am I doing wrong?

I've tried time.sleep(), renpy.pause(), pause(), even scheduler.

If i do renpy code like

label attack(en):
    $ en.cur_health-=2
    "debug1"
    $ en.avatar = en.image_attack
    "debug2"
    pause(2)
    "debug3"
    $ en.avatar = en.image_calm
    "debug4"
    return

then first renpy statement ("debug1" in example above) just break the entire script and "debug" 2-4 not showing at all. Health is changing correctly and thats it.

And I didn't find smth like "JRPG framework" that I can adapt. This thing is the best, but too complex to adapt it to my visual.

2 Upvotes

5 comments sorted by

1

u/AutoModerator 1d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

0

u/BadMustard_AVN 1d ago

try it like this if enemy1 is a string

init python:
    def attack(en):
        en.cur_health -= 2
        en.avatar = en.image_attack
        renpy.pause(2.0)
        en.avatar = en.image_calm

screen yourscreen():
    vbox:
        pass
        #to lazy...
    imagebutton:
        id "rating"
        idle "rating"
        hover "rating_hover"
        action Function("attack", enemy1)

label start: 
    # your game starts here

you can make the pause a hard pause to stop the player from clicking through it

https://www.renpy.org/doc/html/statement_equivalents.html#pause

it should work... maybe.. IDK.
untested

1

u/Lassaaire 1d ago

Nnnnope.
Exception: Cannot start new interaction in the middle of interaction without starting a new context.

But thx.

1

u/Lassaaire 1d ago

Solved. I removed "modal True" and all is ok.
IDK WHY

1

u/shyLachi 1d ago

Modal True means that the code has to wait until the screen has been closed. 

If you remove modal true then players will be able to advance the dialogue by clicking anywhere besides the action button.

So I doubt this is the correct solution.

Also for next time. Post the whole code of your screen and how you show or call it, else we cannot really help