Help on animated counter

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
User avatar
LittleRainySeasons
Regular
Posts: 44
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Help on animated counter

#1 Post by LittleRainySeasons »

This is something that is bugging me for months and I need help on this.
So what I'm doing is a score counter. And my plan is that the numbers would roll when points automatically gets deducted or earned in the game.

I used this code to do it:

Code: Select all

label arcadetesuto:
    $ chances = renpy.random.randint(1, 2)
    $ winningtickets = 0
    
    $ cash -= 50
    
    if chances == 1:
        $ winningtickets += 50
        show screen arcadetest(50)
        
        "Congratulations! You win!!"
        
    else:
        "Better luck next time!"
        
    $ tickets += winningtickets
    
    hide screen arcadetest
    jump playarcade
    
screen arcadetest(maximum):
    $ winningtickets = tickets
    text "[tickets]" pos (645, 225) font "gui/PressStart2P-Regular.ttf" size (18) color ("#f83800")
    if winningtickets < maximum:
        timer 0.01 action [SetScreenVariable("winningtickets", winningtickets +2), SetScreenVariable("tickets", winningtickets)] repeat True
Unfortunately there is a problem:
It only shows the rolling on the first win but in the second win, it does not add up at all.

Pardon if my coding isn't that good. I'm trying my best to come up with a solution for it and I can't seem to figure it out.

philat
Eileen-Class Veteran
Posts: 1920
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Help on animated counter

#2 Post by philat »

Doesn't look like that would run (for instance, there's no screen variable tickets) but I assume it's down to editing for posting. In any case, here's a simple running counter.

Code: Select all

default tickets = 0

label start:
    "Start"
    $ tickets += 50
    show screen running_counter(tickets, 50)
    pause
    hide screen running_counter
    $ tickets -= 20
    show screen running_counter(tickets, -20)
    pause

screen running_counter(end, increment):
    default current_val = end - increment
    text str(current_val)
    if increment > 0:
        if current_val < end:
            timer 0.01 action SetScreenVariable("current_val", current_val+1) repeat True
    else:
        if current_val > end:
            timer 0.01 action SetScreenVariable("current_val", current_val-1) repeat True

User avatar
LittleRainySeasons
Regular
Posts: 44
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Re: Help on animated counter

#3 Post by LittleRainySeasons »

philat wrote: Sun Apr 07, 2024 9:42 pm Doesn't look like that would run (for instance, there's no screen variable tickets) but I assume it's down to editing for posting. In any case, here's a simple running counter.

Code: Select all

default tickets = 0

label start:
    "Start"
    $ tickets += 50
    show screen running_counter(tickets, 50)
    pause
    hide screen running_counter
    $ tickets -= 20
    show screen running_counter(tickets, -20)
    pause

screen running_counter(end, increment):
    default current_val = end - increment
    text str(current_val)
    if increment > 0:
        if current_val < end:
            timer 0.01 action SetScreenVariable("current_val", current_val+1) repeat True
    else:
        if current_val > end:
            timer 0.01 action SetScreenVariable("current_val", current_val-1) repeat True
I tried this code and somehow it didn't work. It says that "current_val" isn't defined.

philat
Eileen-Class Veteran
Posts: 1920
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Help on animated counter

#4 Post by philat »

Nope. It works.

User avatar
LittleRainySeasons
Regular
Posts: 44
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Re: Help on animated counter

#5 Post by LittleRainySeasons »

philat wrote: Mon Apr 08, 2024 11:48 pm Nope. It works.
I get an error when I tried it.

Edit: I did finally get it to work but the number always drop to "49" when it decreases by 50.

Post Reply

Who is online

Users browsing this forum: BBN_VN