"Day name" stuck in first value

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
Mai Goe
Newbie
Posts: 2
Joined: Sat Oct 15, 2016 2:46 am
Contact:

"Day name" stuck in first value

#1 Post by Mai Goe »

I hope the topic subject is not too confusing.
So I tried a code from another thread, but it's posted in 2012 so not sure if I should post my question there. It's basically converts day number to day name.

Code: Select all

label start:
    label days:
        scene bg park
        show eileen happy at center
        with dissolve
        e "We will now execute the days system."
        $ day = 0
        $ day_name_values = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thrusday", "Friday", "Saturday"]
        $ day_name = day_name_values[(day%7)]
        label dayprogress:
        menu:
            "sleep":
                $ day += 1
                e "Today is Day [day], [day_name]."
                jump dayprogress
When I try running the game, the number of day as in [day] proceeds as I click the "sleep" choice. However the [day_name] stuck in "Sunday". I wonder what did I do wrong, perhaps it's a problem with the syntax?
Please help me, thanks!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: "Day name" stuck in first value

#2 Post by Per K Grok »

Mai Goe wrote: Sat Sep 15, 2018 12:50 pm [
When I try running the game, the number of day as in [day] proceeds as I click the "sleep" choice. However the [day_name] stuck in "Sunday". I wonder what did I do wrong, perhaps it's a problem with the syntax?
Please help me, thanks!
day_name is not updated because it is under 'label day'.
to get it to update you need to have it under 'label dayprogress'

Also be careful on how you indent the code.

Code: Select all

label start:

label days:
    scene bg park
    show eileen happy at center
    with dissolve
    e "We will now execute the days system."
    $ day = 0
    $ day_name_values = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thrusday", "Friday", "Saturday"]

label dayprogress:
    menu:
        "sleep":
            $ day += 1
            $ day_name = day_name_values[(day%7)]
            e "Today is Day [day], [day_name]."
            jump dayprogress

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: "Day name" stuck in first value

#3 Post by trooper6 »

None of that is going to work because variables don't automatically update. Also you need to declare your variables using default (if the variable will change) or define (if it won't), outside any block. Here is a way to get what you want using a class.

Code: Select all

init python:
    class Calendar(object):
        def __init__(self):
            self.number = 0
            self.names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thrusday", "Friday", "Saturday"]

        @property
        def name(self):
            return self.names[self.number%7]

default day = Calendar()

# The game starts here.

label start:

    scene black
    "We will now test the say system. Please take note of indentation."
    menu dayprogress:
        "sleep":
            $day.number += 1
            "Today is Day [day.number], [day.name]"
            jump dayprogress
        "end":
            pass

    "Game over."

    return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Mai Goe
Newbie
Posts: 2
Joined: Sat Oct 15, 2016 2:46 am
Contact:

Re: "Day name" stuck in first value

#4 Post by Mai Goe »

trooper6 wrote: Sat Sep 15, 2018 4:43 pm None of that is going to work because variables don't automatically update. Also you need to declare your variables using default (if the variable will change) or define (if it won't), outside any block. Here is a way to get what you want using a class.
It works, thank you very much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]