Using Ren'Py Code In Python

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
Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Using Ren'Py Code In Python

#1 Post by Nero »

I was just wondering how to make exact same thing from Ren'Py just coded in Python language. My question is mainly based around labels in Ren'Py which can't be used in Python.

So here is example that's how code looks in Ren'Py:

Code: Select all

label BATTLE_SKELETON:
    if current_player.NAME == "Bob":
        
        if current_player.STUN_DURATION < 1:
            
            $ bob.CURRENT_PLAYER_TURN_TRUE()
            $ enemy_members_list[res].ADD_ATTACK_MARKER()
            $ res = ui.interact()
            
            label BOB_BASIC_ATTACK:
                $ enemy_members_list[res].REMOVE_ATTACK_MARKER
                "Lets jump back to the label!"
                jump BOB_BASIC_ATTACK

And here is exact same thing just written as Function so how can I make labels and jump to it like you wold do in Ren'Py?

Code: Select all

    def BATTLE_SKELETON(self):
        if current_player.NAME == "Bob":
            
            if current_player.STUN_DURATION < 1:
                
                bob.CURRENT_PLAYER_TURN_TRUE()
                res = ui.interact()
                enemy_members_list[res].ADD_ATTACK_MARKER()
                
                # <------------------------------------------ This line what do I put inside here label can't be used 
                
                    enemy_members_list[res].REMOVE_ATTACK_MARKER
                    renpy.say(battle_narrator, "Lets jump back to the label!")
                    
                    # <-------------------------------------- And here how do I make jumps like in Ren'Py?

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using Ren'Py Code In Python

#2 Post by PyTom »

You can't do it. It's not part of Python.

Python is a structured programming language, which means control tends to occur in things like loops. By contrast, Ren'Py is an unstructured language, which is okay because visual novel programs tend not to loop.

A pattern I often use in my own games is.

Code: Select all

$ logic = GameLogic()

while True:
     $ event = logic.step()

     if event == "whatever":
          "Whatever."
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Using Ren'Py Code In Python

#3 Post by Nero »

Yes I know they can't be used I just wanted to know the example of making an "label similar feature" in Python. I'm trying to use your example but I'm getting error GameLogic not defined even if it is defined? Can you please provide me with full example of how things should be working in action?

I'm needing this because I prefer to have battle engine written in Python while I use Ren'Py for story and screen editing, effects etc...

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using Ren'Py Code In Python

#4 Post by PyTom »

You can't do it. Python doesn't allow something like a Ren'Py label.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Using Ren'Py Code In Python

#5 Post by Nero »

Aw that's a shame it would be insanely helpful with coding of loops. Oh well thanks for the answer guess I will have to combine labels,jumps and functions together.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Kocker, Ocelot, Semrush [Bot]