Ren'Py Help with Ren´py code (beginner) ... add "timer"

Creator13

Starting developer
Game Developer
Jul 26, 2023
93
30
Hello, I am working with Ren´py and I tried to make my own minigame. In my game I used modified scrip from lemmasoft. Anyway...I want to made my own minigame (I use a lot from other scrip therefor there are still "red_hood" and "wolf"). My new minigame will work on principle of "rock-paper-scissors". The script has basic working rules, but I wanted to add "timer" But..since the scrip repeat itself in loop...timer continue . If you will have some idea, I will be glad. If you want..use the script free.
Without timer the script is working. Just need to clean from not necessary leftowers.

P.S. Right now used pictures will not be in final versions, it was just to see how it is working.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
But..since the scrip repeat itself in loop...timer continue . If you will have some idea, I will be glad.
Hmm, from your code, I get that the countdown apply for the whole battle... So, the answer is basic: do not reset it each time a round is played.


This being said, there's a lot of issues in the code:
  • You use a while loop, but like you systematically jump at the starts of the label, it is never effectively used.
  • At the end of this useless while loop, you've an useless if test. "hp_round" will always be equal to 0 when Ren'Py will it come to that line.
  • The time decrease every 0.01 second, but the bar express the value in second.
  • It's not really a rock-paper-scissor since the player know beforehand what is its opponent choice.
    time is a semi-reserved keyword (for the time module), it SHOULDN'T be used to name a variable.
  • And, as I said, you reset the timer at the starts of every round, while your code seem to indicate that it apply for the whole battle.


Python:
label battle_game:
    "START GAME. Goblin has first turn!"   
    scene goblin_game2:
        zoom(0.67)
    r "Okey...let´s play. Show me your cast!"
    wg "You will lose human scum!"

    # Reset of the values.
    $ round_hp = 5
    $ timer_range = 5
    $ timer_jump = 'battle_lost_a'
    # As I said, "time" SHOULDN'T be a variable name.
    $ timeLeft = 5

    # Start the countdown.
    show screen countdown

    # Will proceed the /round/ code as long as there's round to play.
    while (round_hp > 0):

         # One more round played
         $ round_hp -= 1

        # Opponent turn
        # There's no need for two variables containing the same value...
        # Especially when you don't use the second one.
        $ spell_cast = renpy.random.randint(1, 5)

        # Player choice.
        menu:
            
            "FIRE":
                "Clara cast FIRE"
                # This choice loose against those choices.
                $ looseAgainst = [1, 2, 3]
                # This choice win against those choices.
                $ winAgainst = [4, 5]
                
            "WATER":
                "Clara cast WATER"
                $ looseAgainst = [2,3,4]
                $ winAgainst = [1,5]

            "Wind":
                "Clara cast WIND"
                $ looseAgainst = [3,4,5]
                $ winAgainst = [1,2]

            "Electric":   
                "Clara cast ELECTRIC"
                $ looseAgainst = [4,1,5]
                $ winAgainst = [2,3,]

            "Earth":
                "Clara cast EARTH"
                $ looseAgainst = [5,1,2]
                $ winAgainst = [3,4]

        # Display what was the opponent choice.
        if spell_cast == 1: 
            #  Give an alias name to the image, to be able to remove it easily.
            show fire as casted_speel
        elif spell_cast == 2:
            show water as casted_speel
        elif spell_cast == 3:
            show wind  as casted_speel
        elif spell_cast == 4:
            show electric as casted_speel
        elif spell_cast == 5:
            show earth as casted_speel
        
        # Resolve the fight
        # The opponent chose a wining move.
        if spell_cast in looseAgainst:
            # Do you really need to compute "value + 0" ? :/
            #$ red_hood_hp = min(red_hood_hp+0, red_hood_max_hp)
            $ wolf_hp = min(wolf_hp+1, wolf_max_hp)
            "You loose !"
        # The opponent chose a loosing move.
        elif spell_cast in winAgainst:
            $ red_hood_hp = min(red_hood_hp+1, red_hood_max_hp)
            "You won !"

        # remove the opponent hand
        hide casted_speel

        # Will automatically loop as long as there's still round to play.

    # The battle is finished, stop the countdown.
    hide screen countdown

    hide screen simple_stats_screen
    
    # As I said, totally useless.
    #if round_hp <= 0:

    if red_hood_hp <= wolf_hp:
        "You didn´t win! :("
        hide ferocity_beast_wound2
        hide ferocity_beast_wound
        hide clara_dress_battle_pan2
        hide clara_dress_battle_pan
        scene clara_ferocity_beast:
            zoom(0.67)
        pause
        jump battle_lost_a
            
    else:
        r "Hey...it is five rounds match. I have more points already!"
        r "I wiiiin!!!!! Yeee"
        r "Take it, yeaahh, f#ck you little green freak!"
        hide spider4
        hide spider3
        hide spider2
        show ferocity_beast_wound3 at right
        jump end_battle

screen countdown():
    timer 0.01 repeat True action If( timeLeft > 0, SetVariable('timeLeft', timeLeft - 0.01), [Hide('countdown'), Jump(timer_jump)])

    # "*100" because you count the time in hundredth of second, not in second.
    bar value timeLeft*100 range timer_range*100 xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve
 
  • Like
Reactions: Creator13

Creator13

Starting developer
Game Developer
Jul 26, 2023
93
30
Hello. Thank you for you support and answer. The time count I take from: So..I tried to fit it in my code somehow.

You made it so much simpler :) I just used a little what I know. I didn´t know that $ looseAgainst,$ winAgainst exist :D

Yeah...it is not exactly rock-paper-scisor (or + lizard, Spock), but if it would be only on random luck, it would not need any intention from player. Like this, the player need to think about answer. With timer it is better. Player then haven´t a lot of time to choose.

The original code didn´t have "jump" each click in menu, BUT I didn´t know how to restart "spell_cast" each round. First I have it as part of "menu". Player could start each round manually clicking on it. Then I didn´t know how make player to click on first line of menu and then choose from rest :D so...I put it on beginning, where it start automatically and then player choose answer in menu. And there I ad jump..so it start again with new random spell_cast.

I wanted also use buttons instead of menu, but all I found about buttons is that "action Jump (.... I didn´t find how to made button $ looseAgainst,$ winAgainst. Buttons would not cover screen as "menu".

If I have button:
imagebutton:

xysize (300, 300)
align (0.5, 0.5)

idle new_pic_bw
hover new_pick_color

action Jump("new_location")

How I made Action be $ looseAgainst,$ winAgainst?

Anyway. I learn something new. Thank you for that.
 
Last edited: