Trouble creating a point and click game with a time system

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
HazyDistress
Newbie
Posts: 2
Joined: Fri Nov 24, 2023 1:09 pm
Contact:

Trouble creating a point and click game with a time system

#1 Post by HazyDistress »

I'm trying to set up a sandbox-ish point and click game in Ren'py. I've seen other games do similar things in Ren'py, so I think what I'm trying to do is possible.

I have labels for different locations that change the scene when jumped to, and imagebuttons for things like doors that jump to them when clicked. I'm not sure if it's the right way to do it, but I put "$ renpy.pause(hard=True)" at the end of the location labels to allow the player to "move" around. It seems to work great so far. I also have a working time system, and an imagebutton that advances time by an increment of 1.

The problem is that whenever I use the TimeForward button to advance time, it also transports me back and forth between the bedroom and the hallway with each click. I've tried changing different things, and sometimes it changes which "rooms" I'm transported to. If I change the "jump bedroom" to "jump hallway" under the start label, it no longer bounces me back and forth, but it transports me back to the hallway if I'm in the bedroom. I think the problem may have something to do with the TimeForward button "bypassing" the pauses? I tried putting "$ renpy.pause(hard=True)" at the end of the "timechange" label, that stops the "transporting" but also stops the background images from changing with the time of day.

Hopefully that makes some sense, basically I'm trying to get the player to be able to navigate to different "rooms" by clicking on imagebuttons, and also to be able to advance time by clicking on other imagebuttons, but not to transport them to random rooms when clicking the advance time buttons. I'm sure it's a stupid problem, but I have no idea what I should be doing differently. Here is the full script for the game so far. It's not very long, I'm trying to get everything working before I add more stuff. I'd really appreciate it if someone who knows what they're doing could give me a hint as to what I'm doing wrong. Thank you in advance for any help.

Code: Select all

define p = Character("Player")

# Time

label timechange(increment=1):
    $ timeofdaynumber += increment

    if timeofdaynumber == 1:
        $ timeofday = " Early Morning"
    elif timeofdaynumber == 2:
        $ timeofday = "Mid Morning"
    elif timeofdaynumber == 3:
        $ timeofday = "Late Morning"
    elif timeofdaynumber == 4:
        $ timeofday = "Early Day"
    elif timeofdaynumber == 5:
        $ timeofday = "Mid Day"
    elif timeofdaynumber == 6:
        $ timeofday = "Late Day"
    elif timeofdaynumber == 7:
        $ timeofday = "Early Evening"
    elif timeofdaynumber == 8:
        $ timeofday = "Mid Evening"
    elif timeofdaynumber == 9:
        $ timeofday = "Late Evening"
    elif timeofdaynumber == 10:
        $ timeofday = "Early Night"
    elif timeofdaynumber == 11:
        $ timeofday = "Mid Night"
    elif timeofdaynumber == 12:
        $ timeofday = "Late Night"
    elif timeofdaynumber >= 13:
        $ timeofdaynumber = 1
        $ timeofday = "Morning"
        $ dayofweeknumber += 1
        $ totaldaysnumber += 1
        $ monthday += 1
    if dayofweeknumber == 1:
        $ dayofweek = "Monday"
    elif dayofweeknumber == 2:
        $ dayofweek = "Tuesday"
    elif dayofweeknumber == 3:
        $ dayofweek = "Wenesday"
    elif dayofweeknumber == 4:
        $ dayofweek = "Thursday"
    elif dayofweeknumber == 5:
        $ dayofweek = "Friday"
    elif dayofweeknumber == 6:
        $ dayofweek = "Saturday"
    elif dayofweeknumber == 7:
        $ dayofweek = "Sunday"
    elif dayofweeknumber >= 8:
        $ dayofweeknumber = 1
    else:
        $ timeofday = "ERROR"
    if totaldaysnumber == 1:
        $ monthday = 1
        $ month = "January"
    elif totaldaysnumber == 31:
        $ monthday = 1
        $ month = "February"
    elif totaldaysnumber == 59:
        $ monthday = 1
        $ month = "March"
    elif totaldaysnumber == 90:
        $ monthday = 1
        $ month = "April"
    elif totaldaysnumber == 120:
        $ monthday = 1
        $ month = "May"
    elif totaldaysnumber == 151:
        $ monthday = 1
        $ month = "June"
    elif totaldaysnumber == 181:
        $ monthday = 1
        $ month = "July"
    elif totaldaysnumber == 212:
        $ monthday = 1
        $ month = "August"
    elif totaldaysnumber == 243:
        $ monthday = 1
        $ month = "September"
    elif totaldaysnumber == 273:
        $ monthday = 1
        $ month = "October"
    elif totaldaysnumber == 304:
        $ monthday = 1
        $ month = "November"
    elif totaldaysnumber == 334:
        $ monthday = 1
        $ month = "December"
    elif totaldaysnumber >= 366:
        $ monthday = 1
        $ month = "January"
    return

default timeofdaynumber = 1
default timeofday = "Early Morning"
default dayofweeknumber = 1
default dayofweek = "Monday"
default totaldaysnumber = 1
default monthday = 1
default month = "January"

screen TimeDisplay:
    text "[timeofday]" ypos 0.85 xpos 0.05
    text "[dayofweek]" ypos 0.9 xpos 0.05
    text "[month] [monthday]" ypos 0.8 xpos 0.05

screen TimeForward:
    imagebutton:
        pos (936, 11, 83, 79)
        idle "time_forward"
        hover "time_forward_hover"
        action Call("timechange")

# Locations

screen button_home_bedroom_door():
    layer "master"
    imagebutton:
        if timeofdaynumber >= 7:
            idle "button_home_bedroom_door_night"
        else:
            idle "button_home_bedroom_door_day"

        if timeofdaynumber >= 7:
            hover "button_home_bedroom_door_night_hover"
        else:
            hover "button_home_bedroom_door_day_hover"
        pos (225, 188, 184, 340)
        action Jump("hallway")

screen button_home_hallway_door_01():
    layer "master"
    imagebutton:
        if timeofdaynumber >= 7:
            idle "button_home_hallway_door_01_night"
        else:
            idle "button_home_hallway_door_01_day"

        if timeofdaynumber >= 7:
            hover "button_home_hallway_door_01_night_hover"
        else:
            hover "button_home_hallway_door_01_day_hover"
        pos (176, 281, 127, 242)
        action Jump("bedroom")

label bedroom:
    if timeofdaynumber >= 7:
        show location_home_bedroom_evening
    else:
        show location_home_bedroom_day

    show screen button_home_bedroom_door
    $ renpy.pause(hard=True)

label hallway:
    if timeofdaynumber >= 7:
        scene location_home_hallway_night
    else:
        scene location_home_hallway_day

    show screen button_home_hallway_door_01
    $ renpy.pause(hard=True)

# Game Start

label start:

    show screen TimeDisplay
    show screen TimeForward

    jump bedroom

    p "testing!"

    return

User avatar
m_from_space
Miko-Class Veteran
Posts: 889
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Trouble creating a point and click game with a time system

#2 Post by m_from_space »

HazyDistress wrote: Fri Nov 24, 2023 2:19 pm The problem is that whenever I use the TimeForward button to advance time, it also transports me back and forth between the bedroom and the hallway with each click.
A label in Renpy script has to end with either a return or a jump statement, otherwise the game pointer will just move through that label to whatever comes next in the code. It's not like a function in Python where you don't have to define the end of the function with return (which I still like doing to be honest). It's more like a "goto" target, if you know what I mean. Indentation won't stop the script at the end of a label.

So in your case after the "bedroom", it will reach the "hallway", and after that the "start" label and loop.

-----

Code: Select all

define p = Character("Player")

# Time

label timechange(increment=1):
    $ timeofdaynumber += increment

    if timeofdaynumber == 1:
        $ timeofday = " Early Morning"
    elif timeofdaynumber == 2:
        $ timeofday = "Mid Morning"
    elif timeofdaynumber == 3:
        $ timeofday = "Late Morning"
    elif timeofdaynumber == 4:
    ...
There is an easier way of doing things like this (also with months and whatnot):

Code: Select all

define daytimes = ["Early Morning", "Mid Morning", "Late Morning"]

# the first element is always at index 0
default timeofdaynumber = 0

label timechange(increment=1):
    $ timeofdaynumber += increment
    $ timeofday = daytimes[timeofdaynumber]
    ...

HazyDistress
Newbie
Posts: 2
Joined: Fri Nov 24, 2023 1:09 pm
Contact:

Re: Trouble creating a point and click game with a time system

#3 Post by HazyDistress »

m_from_space wrote: Sat Nov 25, 2023 7:34 am A label in Renpy script has to end with either a return or a jump statement, otherwise the game pointer will just move through that label to whatever comes next in the code. It's not like a function in Python where you don't have to define the end of the function with return (which I still like doing to be honest). It's more like a "goto" target, if you know what I mean. Indentation won't stop the script at the end of a label.

So in your case after the "bedroom", it will reach the "hallway", and after that the "start" label and loop.
Thanks for helping! I don't know if it's a legit way to do things, but I managed to get the issue resolved by making the room labels jump to themselves like:

Code: Select all

label bedroom:
    if timeofdaynumber >= 10:
        scene location_home_bedroom_night
    elif timeofdaynumber >= 7:
        scene location_home_bedroom_evening
    else:
        scene location_home_bedroom_day

    show screen button_home_bedroom_door
    show screen button_home_bedroom_bed
    $ renpy.pause(hard=True)
    jump bedroom
    return
Not sure if the return is still necessary after the jump?

Thanks for the advice on the time system, that's really helpful.

User avatar
m_from_space
Miko-Class Veteran
Posts: 889
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Trouble creating a point and click game with a time system

#4 Post by m_from_space »

HazyDistress wrote: Mon Nov 27, 2023 9:13 am Not sure if the return is still necessary after the jump?
It will never reach that return, so it's a useless statement in this case. By the way, returning only makes sense if you called the label instead of jumping to it.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]