Page 1 of 1

Using Ren'Py Code In Python

Posted: Fri Dec 08, 2017 12:57 am
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?

Re: Using Ren'Py Code In Python

Posted: Fri Dec 08, 2017 2:39 am
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."

Re: Using Ren'Py Code In Python

Posted: Fri Dec 08, 2017 11:19 am
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...

Re: Using Ren'Py Code In Python

Posted: Sat Dec 09, 2017 1:15 am
by PyTom
You can't do it. Python doesn't allow something like a Ren'Py label.

Re: Using Ren'Py Code In Python

Posted: Sat Dec 09, 2017 8:20 am
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.