Getting a certain item once a day / init block problem

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
Cube
Regular
Posts: 84
Joined: Tue Jul 08, 2014 1:00 pm
Completed: You and Me | Love is in Bloom
Projects: Ego Holic
Tumblr: qbstudios
itch: qbstudios
Contact:

Getting a certain item once a day / init block problem

#1 Post by Cube »

I've seen this neat little code and wanted to try it, since it's stuff even I understand ^^"

To make it fit my purposes, I had to change it a bit, but now I'm stuck.

What I want: Every day the player opens the game, they'll be rewarded with 10 coins. (They only get them once per day.) The player can accumulate as many coins as they want - to beat the game, they need to buy a key for a certain amount of coins.

What I have so far:

Code: Select all

## script.rpy for a game in seven days
## original base code by nicolas (probablement.net)

## TIME
init -1 python:
    import time
    time = time.localtime(time.time()).tm_wday
    days = ['Monday',    # 0
            'Tuesday',   # 1   
            'Wednesday', # 2
            'Thursday',  # 3
            'Friday',    # 4
            'Saturday',  # 5
            'Sunday']    # 6

## START
label start:
   
    # What time is it?
    $day = time
    $dayname = days[time]

   
    # Shared beginning.
    centered "[dayname]"
    "I woke up."

    jump gotoday

## GO TO DAY
label gotoday:
   
    # Jump to daily script.
    if   day == 0:
        jump mon_start   
    elif day == 1:
        jump tue_start
    elif day == 2:
        jump wed_start
    elif day == 3:
        jump thu_start
    elif day == 4:
        jump fri_start
    elif day == 5:
        jump sat_start
    elif day == 6:
        jump sun_start
    else:
        "Out of time!"
        return

## 0 MONDAY
label mon_start:
    # Check past
    if   persistent.mon_money: ##change to persistent.dayname_money?
        "I already got today's money."
        jump closing

    # Flag day as started
    $persistent.mon_money = True
       
    "Every day, you recieve 10 coins."
   
    menu:
        "Take 10 coins":
            $persistent.mon_money = True
            "You got 10 coins!"
            jump closing
I guess I have to set the flag to False after they recieved the money? But won't the player get another 10 coins when they save and restart the game? (I have to work with persistent data, right?)
Last edited by Cube on Sat Apr 25, 2015 6:38 pm, edited 1 time in total.
ImageImageImage

User avatar
Cube
Regular
Posts: 84
Joined: Tue Jul 08, 2014 1:00 pm
Completed: You and Me | Love is in Bloom
Projects: Ego Holic
Tumblr: qbstudios
itch: qbstudios
Contact:

Re: Getting a certain item once a day

#2 Post by Cube »

Okay, I changed a bit and maybe it's unnecessarily complicated, but I guess this brings me a step closer to my goal:

Code: Select all

screen desktop:
 #Preparing the imagemap
    imagemap:
        ground "gui/menu.png"
        hover "gui/menuhover.png"
       
        hotspot (623, 38, 149, 109) clicked Jump("item")
        hotspot (623, 173, 138, 134) clicked Jump("daycheck")

## TIME
init -1 python:
    import time
    time = time.localtime(time.time()).tm_wday
    days = ['Monday',    # 0
            'Tuesday',   # 1   
            'Wednesday', # 2
            'Thursday',  # 3
            'Friday',    # 4
            'Saturday',  # 5
            'Sunday']    # 6 
   
# The game starts here.
label start:
    
    # What time is it?
    $day = time
    $dayname = days[time]
   
    # Shared beginning.
    centered "[dayname]"
    "I woke up."
    
    jump intro
    
############################################################ INTRO

label intro:

    "Something will happen."

    jump daycheck
    
label daycheck:

    # Jump to daily script.
    if   day == 0:
        jump mon_start   
    elif day == 1:
        jump tue_start
    elif day == 2:
        jump wed_start
    elif day == 3:
        jump thu_start
    elif day == 4:
        jump fri_start
    elif day == 5:
        jump sat_start
    elif day == 6:
        jump sun_start
    else:
        "Out of time!"
        return
    
    
## 0 MONDAY
label mon_start:
    # Check past
    if   persistent.mon_yen:
        "I already got the Monday money."
        jump desktop

    # Flag day as started
    $persistent.mon_started = True
    $persistent.sun_yen = False
       
    "This Monday, I'll get the Monday money."
   
    menu:
        "Get Monday item":
            $persistent.mon_yen = True
            $ money += 10
            "You got the Monday money!"
            jump desktop
           
           
## 1 TUESDAY
label tue_start:
    # Check past
    if   persistent.tue_yen:
        "I already got the Tuesday money."
        jump desktop

    # Flag day as started
    $persistent.tue_started = True
    $persistent.mon_yen = False
       
    "This Tuesday, I'll get the Tuesday money."
   
    menu:
        "Get Tuesday money":
            $persistent.tue_yen = True
            $ money += 10
            "You got the Tuesday money!"
            jump desktop
           
label desktop:
    
    call screen desktop
There's still a problem (who would've thought?) - I got my Saturday money and after clicking the 'daycheck' button, I get the message that I've already recieved the money, BUT it says so on Sunday, too.
It's half past midnight (Sunday) now and when I load my savegame (and click the 'daycheck' button), I still get the message that I've already got my SATURDAY money.

Maybe it's because of the
init -1 python:
import time
time = time.localtime(time.time()).tm_wday
part?
I thought init block don't save any data/variables? Does that mean that init blocks run even after/shortly before I load my savegame?
ImageImageImage

Post Reply

Who is online

Users browsing this forum: Exiscoming, Google [Bot], Semrush [Bot]