Imagebuttons and creating a RPG combat move order

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
dlugosi
Newbie
Posts: 1
Joined: Mon Dec 05, 2022 2:02 pm
Contact:

Imagebuttons and creating a RPG combat move order

#1 Post by dlugosi »

My code probably looks really amateurish apologies, I am still fairly new to screen language and just created a simple test game to see if I could get this to work. Really appreciate if anyone can point me in the right direction with what to do here.


Basic idea: Player gets two actions. Each action needs an attack and a target.

Problem = How do I get renpy to remember the variables I set/know if the player has already used up an action while using image buttons.

I tried using if statements to no avail, especially since I already figure that jumping back to the main_combat screen invalidates the variables I changed since its going back to a previous state in the game.


You can see I have action 1 set but I cant even get that to function properly nor do I know the best way of having renpy check if action 1 has been set or not given how my labels are setup right now.

Code: Select all



label start:
    $ attack = "nothing"
    $ target = "no one"
    $ action1 = "nothing"
    $ action2 = "not do a damn thing"
label main_combatscreen:

    e "Ok so first you are going to do [action1], then you will [action2]"
    
    call screen attack_UItest



#combat screen with a button labeled punch
    

    screen attack_UItest():
        add "smoke"
        modal True

        imagebutton auto "punch_%s":
            focus_mask True
            action SetVariable("attack", "punch"), Jump ("target")

label target:
    call screen target_UItest
    e "You are now using, [attack]. Who would you like to do that to?"
    
    screen target_UItest():
        add "smoke"
        modal True


#first target option

        imagebutton auto "henry_%s":
            focus_mask True
            action SetVariable("target", "Henry"), SetVariable ("action1", target+attack), Jump ("main_combatscreen")

#second target option


        imagebutton auto "philip_%s":
            focus_mask True
            action SetVariable("target", "Philip"), SetVariable ("action1", target+attack,), Jump ("main_combatscreen")
            

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Imagebuttons and creating a RPG combat move order

#2 Post by Alex »

dlugosi wrote: Mon Dec 05, 2022 2:06 pm ...
Basic idea: Player gets two actions. Each action needs an attack and a target.

Problem = How do I get renpy to remember the variables I set/know if the player has already used up an action while using image buttons.
...
Try something like:

Code: Select all

screen test_scr():
    vbox:
        align(0.5, 0.2)
        textbutton "Action 1" action Return("action_1")
        textbutton "Action 2" action Return("action_2")

default variable_one = ""
default variable_two = ""

label start:
    "test"
    "choose first action"
    call screen test_scr
    $ variable_one = _return
    "choose second action"
    call screen test_scr
    $ variable_two = _return

    "you've choose [variable_one] and [variable_two]"
    jump start

For turn-based game I would suggest you:
- to make a combat loop,
- to call UI-screen at every players turn and get result of player's interactions with it (check the Return action - https://www.renpy.org/doc/html/screen_a ... tml#Return),
- evaluate this result and do corresponding actions,
- check the combat state (win/lose).

Check this samples of code:
viewtopic.php?f=51&t=18047&start=15#p395926
viewtopic.php?f=51&t=18047&start=15#p395928

Post Reply

Who is online

Users browsing this forum: Google [Bot]