Ren'Py Renpy sandbox help

SweetGames

Newbie
Jan 1, 2023
33
4
Hello I am working for a while on a renpy sandbox. and have some system problems. Looking for someone who can help me fix the problems. please Private Message.

thank you
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
To what GNVE said, I want to add that it's a public forum for a good reason.

Whatever the issue one have, it's really unlikely that it is and will stay the only one to have it. Therefore a public answer help everyone and contribute to the community.


Edit: By the way, sorry GNVE, had a power outage some times ago while answering your post regarding AI bots. It lasted the whole night, and I just remember now that I never answered, without having a fucking clue regarding where the thread can be :(
 

SweetGames

Newbie
Jan 1, 2023
33
4
ok, so my problem is that i have a time system that i want to connect to the navigation.

on the map are 11 imagebuttons, each of them should represent a destination. The each of these 11 imagabuttons opens a window with info about the travel location and its 3 buttons foot, bus, car.

so you click on foot, bus or car and jump to the desired travel label.

i get that but if i jump for example from home to park the new starting point is not home but park.
from there the travel times to each location are different than from home.


example: player travels from home to park + 40min
player is in park goes back to map + 0min
player goes back to park + 0

and there is my problem, here he counts again 40+ by foot or 20 by bus or 10 by car. But he is still in the park. Only when other travels there. would be counted again at the park +.


home > by foot to the park 40min
> by bus to the park 20min
> by car to park 10min

home > to home 0 min

home > walk to fitness 50min
> by bus to fitness 25min
> by car to fitness 15min

home > walk to store 40min
> by bus to the store 20min
> by car to the store 10min

store > walk to park 20min
> by bus to the park 10min
> by car to park 5min

park > walk to fitness 10min
> by bus to fitness 5min
> by car to fitness 2min

etc. From each location it should have different travel times.

have already tried it on several ways but can't get it to work.

thanks
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
have already tried it on several ways but can't get it to work.

Hmm...

Not necessarily the optimal approach, but a dict is one way to solve this:

/!\ Warning, wrote in the fly. There's possible typos /!\
Python:
#  Travel time from /key/ to all the destination.
#  The tuple being ordered: walk, bus, car.
define travelTime = { "park": { "home": ( 20, 10, 5 ), "store": ( 15, 7, 3 ), "park": None },
                                 "home": { "home": None, "store": ( 10, 5, 2 ), "park": (20, 10, 5 ) },
                                 [...] }

# Where the player currently is.
default currentLocation = "home"

screen travelUI():

    imagebutton:
        auto "home_%s.png"
        # While be not sensitive (so not clickable) if there's no travel value, from the
        # current location to "home" ; what mean that it's where we are.
        sensitive not travelTime[currentLocation]["home"] is None
        # A screen to select how to move, passing it the expected destination.
        action Show( "moveScreen", "home" )

    imagebutton:
        auto "park_%s.png"
        sensitive not travelTime[currentLocation]["park"] is None
        action Show( "moveScreen", "park" )

    [...]

screen moveScreen( where ):

    vbox:
        textbutton "walk":
            # Add the travel time by feet from the current location to the destination.
            # Hide the current screen.
            # Jump to an entry label for the destination.
            action [ SetVariable( "currentTime", currentTime + travelTime[currentLocation][where][0] ), Hide(), Jump( where + "Hub" ) ]

        textbutton "bus":
            action [ SetVariable( "currentTime", currentTime + travelTime[currentLocation][where][1] ), Hide(), Jump( where + "Hub" ) ]

        textbutton "car":
            action [ SetVariable( "currentTime", currentTime + travelTime[currentLocation][where][2] ), Hide(), Jump( where + "Hub" ) ]


# The entry label for the park
label parkHub:
    # Update the current location, then do whatever you want.
    $ currentLocation = "park"
    [...]

label homeHub:
    $ currentLocation = "home"
    [...]

[...]

Side note: It should be possible to limit the "travelUI" screen to four lines:
Python:
screen travelUI():

    for location in [ "home", "park", "store" ]:
        imagebutton:
            auto "{}_%.png".format( location)
            action Show( moveScreen, location )

Edit: Typos in the code ; added the forgot warning.
 
Last edited:

GNVE

Active Member
Jul 20, 2018
724
1,184
For code I'm not the best so You probably want to follow AON. One optimization I could see is:

Python:
define travelTime = { "park": { "home": 20, "store": 15, "park": None },
                                 "home": { "home": None, "store": 10, "park": 20},
                                 [...] }
with the bus and car buttons just dividing the base time in 2 and 4 respectively (or whatever you want). Especially with a lot of locations and/or more transport options it might be a little easier to keep the overview. But that might be just personal preference.

Python:
action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where] ), Hide(), Jump( where + "Hub" ) ]

        textbutton "bus":
            action [ SetVariable( currentTime, currentTime + round(travelTime[currentLocation][where] / 2) ), Hide(), Jump( where + "Hub" ) ]

        textbutton "car":
            action [ SetVariable( currentTime, currentTime + round(travelTime[currentLocation][where] / 4 ) ), Hide(), Jump( where + "Hub" ) ]
*please note I have not tested if this actually works in Ren'Py. Might be a little more complicated than I imagine it to be. That is why I generally leave the coding to people like AON who know what they are doing...:sneaky:

Something I want you to consider from a players perspective is that I generally dislike travel times in games. Especially when I don't get clear guidance where the next peace of content is. In some games I literally spend half the day just traveling to various locations to find a nugget of content.
So If you want to add travel time I would strongly suggest also baking in a way to see on the travel screen where the next piece of content is (and whether it is new or if it is a repeatable event.)
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
For code I'm not the best so You probably want to follow AON. One optimization I could see is:

Python:
define travelTime = { "park": { "home": 20, "store": 15, "park": None },
                                 "home": { "home": None, "store": 10, "park": 20},
                                 [...] }
with the bus and car buttons just dividing the base time in 2 and 4 respectively (or whatever you want).
It's what I wanted to do at first, but I noticed that travel like home to fitness and park to fitness do not match the 2 and 4 followed by the other travels.
This said, I followed his approach to not be too confusing, but I agree with you that it would be better.


Python:
action [ SetVariable( currentTime, currentTime + round(travelTime[currentLocation][where] / 2) ), Hide(), Jump( where + "Hub" ) ]
*please note I have not tested if this actually works in Ren'Py.
It works, but personally I would have used int( travelTime[currentLocation][where] / 2 ).
round() will round the value, therefore 1.51 will become 2. This will int() will get rid of the decimal, so 1.99 will still become 1.
But it's a question of personal taste. I come from a time where float values where rarely used, and so I expect 3 / 2 to be equal to 1


Something I want you to consider from a players perspective is that I generally dislike travel times in games. Especially when I don't get clear guidance where the next peace of content is. In some games I literally spend half the day just traveling to various locations to find a nugget of content.
So If you want to add travel time I would strongly suggest also baking in a way to see on the travel screen where the next piece of content is (and whether it is new or if it is a repeatable event.)
I'm tempted to add that personally it's strict time in games that I tend to dislike.

I have nothing against periods (morning, noon, etc.), nor even with generic times (1AM, 2AM, etc) since they are just a 24 periods approach. But strict time, therefore something where minutes also count, it quickly become annoying.
Either it need that you plan your whole day, because you want to catch that even that happen between 14:32 and 14:45. This with the risk to miss it because in between you'll trigger an event that will mess with your planing ; what mean that quickly you do only one event a day, just passing time until you can catch it.
Or it's totally useless, because the event will happen at any time between 14:00 and 14:59. Therefore there's no need for the minutes, and you wonder why you've to be bothered by them.

This doesn't mean that "walking", "taking the bus", "using a car", is a bad idea, but it shouldn't be a question of time.
By example, in Killer Project it permit to have different random scenes, depending on your choice. This while in Super Powered walking will cost you energy, asking for someone to drive you will cost you favors (but can lead to sex), and if I remember correctly taking the bus cost you money. But with both games it will just get you to your destination without having a different impact on the time.
For Super Powered, there's also a notion of distance, there's place that are expected to be too far, and therefore that you can't walk to.
 
  • Like
Reactions: GNVE

GNVE

Active Member
Jul 20, 2018
724
1,184
Don't do this! Doing this is silly but also a little fun (If I where to do a sandbox it might end in the game just because...).

But you could place all buildings on a grid (using excel if need be) and have different modes of travel be advantageous for different distances. (doing it in pseudo code because lazy :ROFLMAO:).
so something like:
home: 1,1
store: 2,1
park: 3,2
church: 4,7
school: 6,7
work: 19,19

now subtract x1 from x2 and y1 from y2
eg store to work 2 - 20 =-17 and 1-20=-18
making sure to invert those two values if negative like in this case
add the values for total distance = 35

now calculate travel time per mode of transport (time to start + (Distance / KMPH *60)
walking: 0 + (35 / 5 * 60) =420
Cycling 5 + (35 / 12 * 60) =300
Car 30 + (35 / 23 * 60) =121
PT 45 + (35 / 25 * 60) =129

but for home to the store it would look like
walking: 0 + (1 / 5 * 60) =12
Cycling 5 + (1 / 12 * 60) =10
Car 30 + (1 / 23 * 60) =32
PT 45 + (1 / 25 * 60) =47

(For the figures I quickly googled speeds for city traffic. the base time is the time it takes to get to your car or bike and park it at the destination. For the bus it assumes having to walk to the stop and having to wait a while.)
 
  • Like
Reactions: anne O'nymous

SweetGames

Newbie
Jan 1, 2023
33
4
Python:
#  Travel time from /key/ to all the destination.
#  The tuple being ordered: walk, bus, car.
define travelTime = { "park": { "home": ( 40, 20, 10), "school": ( 50, 25, 10 ), "sexshop": ( 20, 10, 5 ), "photo": ( 75, 32, 16 ), "shopping": ( 50, 25, 12 ), "nightclub": ( 55, 26, 13 ), "fitnes": ( 10, 5, 2 ), "rent": ( 75, 32, 16 ), "tante": ( 55, 31, 13 ), "cousine": ( 40, 20, 10 ), "park": None },
                                 "home": { "home": None, "park": (40, 20, 10 ), "school": (30, 15, 7 ), "sexshop": (50, 25, 12 ), "photo": (70, 35, 12 ), "shopping": (45, 22, 10 ), "nightclub": (50, 25, 12 ), "fitnes": (45, 22, 11 ), "rent": (50, 25, 12 ), "tante": (15, 7, 3 ), "cousine": (10, 5, 2 ),  },
                                 "school": { "school": None, "park": (50, 25, 12 ), "sexshop": (75, 32, 15 ), "photo": (40, 20, 10 ), "shopping": (35, 17, 8 ), "nightclub": (40, 20, 10 ), "fitnes": (70, 35, 16 ), "rent": (20, 10, 5 ), "tante": (45, 23, 11 ), "cousine": (40, 20, 10 ), "home": (40, 20, 10)  },
                                 "sexshop": { "sexshop": None, "park": (20, 10, 5 ), "school": (75, 37, 18 ), "photo": (85, 42, 21 ), "shopping": (65, 32, 16 ), "nightclub": (70, 35, 17 ), "fitnes": (10, 5, 2 ), "rent": (90, 45, 22 ), "tante": (60, 30, 15 ), "cousine": (50, 25, 12 ), "home": (50, 25, 12)  },
                                 "photo": { "photo": None, "park": (75, 37, 18 ), "school": (40, 20, 10 ), "sexshop": (85, 42, 21), "shopping": (10, 5, 2 ), "nightclub": (10, 5, 2 ), "fitnes": (75, 37, 18 ), "rent": (25, 12, 6 ), "tante": (90, 45, 22 ), "cousine": (80, 40, 20 ), "home": (70, 35, 17)  },
                                 "shopping": { "shopping": None, "park": (50, 25, 12 ), "school": (35, 17, 8 ), "sexshop": (65, 32, 16), "photo": (10, 5, 2 ), "nightclub": (5, 3, 1 ), "fitnes": (55, 27, 13 ), "rent": (35, 17, 8 ), "tante": (65, 32, 16 ), "cousine": (55, 27, 13 ), "home": (45, 22, 11)  },
                                 "nightclub": { "nightclub": None, "park": (55, 22, 11 ), "school": (40, 20, 10 ), "sexshop": (70, 35, 17), "photo": (10, 5, 2 ), "shopping": (5, 3, 1 ), "fitnes": (65, 32, 16 ), "rent": (40, 20, 10 ), "tante": (60, 30, 15 ), "cousine": (50, 25, 12 ), "home": (50, 25, 12)  },
                                 "fitnes": { "fitnes": None, "park": ( 10, 5, 3 ), "school": ( 70, 35, 17 ), "sexshop": ( 10, 5, 3), "photo": ( 75, 37, 17 ), "shopping": ( 55, 22, 11 ), "nightclub": ( 65, 32, 16 ), "rent": ( 80, 40, 20 ), "tante": ( 65, 32, 16 ), "cousine": ( 55, 27, 13 ), "home": (45, 22, 11) },
                                 "rent": { "rent": None, "park": (75, 37, 18 ), "school": (20, 10, 5 ), "sexshop": (90, 45, 22), "photo": (25, 12, 6 ), "shopping": (35, 17, 8 ), "nightclub": (40, 20, 10 ), "fitnes": (80, 40, 20 ), "tante": (65, 32, 16 ), "cousine": (60, 30, 15 ), "home": (50, 25, 12)  },
                                 "tante": { "tante": None, "park": (55, 22, 11 ), "school": (45, 22, 11 ), "sexshop": (60, 30, 15), "photo": (90, 45, 22 ), "shopping": (60, 30, 15 ), "nightclub": (65, 32, 16 ), "fitnes": (55, 22, 11 ), "rent": (65, 32, 16 ), "cousine": (10, 5, 3 ), "home": (15, 7, 3)  },
                                 "cousine": { "cousine": None, "park": (40, 20, 10 ), "school": (40, 20, 10 ), "sexshop": (50, 25, 12), "photo": (80, 40, 20 ), "shopping": (50, 25, 12 ), "nightclub": (55, 22, 11 ), "fitnes": (55, 22, 11 ), "rent": (60, 30, 15 ), "tante": (10, 5, 3 ), "home": (10, 5, 3) },
                                 }



# Where the player currently is.
default currentLocation = "home"

screen travelUI():

    imagebutton:
        xalign 0.51 yalign 0.61 idle "images/citybuttons/home_idle.png" hover "images/citybuttons/home_hover.png"
        # While be not sensitive (so not clickable) if there's no travel value, from the
        # current location to "home" ; what mean that it's where we are.
        sensitive not travelTime[currentLocation]["home"] is None
        # A screen to select how to move, passing it the expected destination.
        action Show( moveScreen, "home" )

    imagebutton:
        xalign 0.65 yalign 0.40 idle "images/citybuttons/park_idle.png" hover "images/citybuttons/park_hover.png"
        sensitive not travelTime[currentLocation]["park"] is None
        action Show( moveScreen, "park" )

    imagebutton:
        xalign 0.33 yalign 0.60 idle "images/citybuttons/school_idle.png" hover "images/citybuttons/school_hover.png"
        sensitive not travelTime[currentLocation]["school"] is None
        action Show( moveScreen, "school" )

    imagebutton:
        xalign 0.66 yalign 0.23 idle "images/citybuttons/sexshop_idle.png" hover "images/citybuttons/sexshop_hover.png"
        sensitive not travelTime[currentLocation]["sexshop"] is None
        action Show( moveScreen, "sexshop" )

    imagebutton:
        xalign 0.24 yalign 0.34 idle "images/citybuttons/photo_idle.png" hover "images/citybuttons/photo_hover.png"
        sensitive not travelTime[currentLocation]["photo"] is None
        action Show( moveScreen, "photo" )

    imagebutton:
        xalign 0.37 yalign 0.34 idle "images/citybuttons/clothesshop_idle.png" hover "images/citybuttons/clothesshop_hover.png"
        sensitive not travelTime[currentLocation]["shopping"] is None
        action Show( moveScreen, "shopping" )

    imagebutton:
        xalign 0.34 yalign 0.27 idle "images/citybuttons/nightclub_idle.png" hover "images/citybuttons/nightclub_hover.png"
        sensitive not travelTime[currentLocation]["nightclub"] is None
        action Show( moveScreen, "nightclub" )

    imagebutton:
        xalign 0.59 yalign 0.28 idle "images/citybuttons/fitnesclub_idle.png" hover "images/citybuttons/fitnesclub_hover.png"
        sensitive not travelTime[currentLocation]["fitnes"] is None
        action Show( moveScreen, "fitnes" )

    imagebutton:
        xalign 0.19 yalign 0.56 idle "images/citybuttons/rentbuilding_idle.png" hover "images/citybuttons/rentbuilding_hover.png"
        sensitive not travelTime[currentLocation]["rent"] is None
        action Show( moveScreen, "rent" )

    imagebutton:
        xalign 0.5 yalign 0.87 idle "images/citybuttons/house1_idle.png" hover "images/citybuttons/house1_hover.png"
        sensitive not travelTime[currentLocation]["tante"] is None
        action Show( moveScreen, "tante" )

    imagebutton:
        xalign 0.61 yalign 0.65 idle "images/citybuttons/house2_idle.png" hover "images/citybuttons/house2_hover.png"
        sensitive not travelTime[currentLocation]["cousine"] is None
        action Show( moveScreen, "cousine" )

define moveScreen = "moveScreen"

screen moveScreen( where ):

    vbox:
        textbutton "walk":
            # Add the travel time by feet from the current location to the destination.
            # Hide the current screen.
            # Jump to an entry label for the destination.
            action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][0] ), Hide(), Jump( where + "Hub" ) ]

        textbutton "bus":
            action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][1] ), Hide(), Jump( where + "Hub" ) ]

        textbutton "car":
            action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][2] ), Hide(), Jump( where + "Hub" ) ]


# The entry label for the park
label parkHub:
    $ currentLocation = "park"     # Update the current location, then do whatever you want.


label schoolHub:
    $ currentLocation = "school"


label sexshopHub:
    $ currentLocation = "sexshop"


label photoHub:
    $ currentLocation = "photo"


label shoppingHub:
    $ currentLocation = "shopping"


label nightclubHub:
    $ currentLocation = "nightclub"


label fitnesHub:
    $ currentLocation = "fitnes"


label rentHub:
    $ currentLocation = "rent"


label tanteHub:
    $ currentLocation = "tante"


label cousineHub:
    $ currentLocation = "cousine"


label homeHub:
    $ currentLocation = "home"


label karte:
    $ saved_state = "karte"
    scene citymap
    hide screen kochen
    hide screen kochenbutton
    hide screen mc_itembuttons
    hide screen shoppingcenter
    show screen ui
    hide screen shoppingcenter
    call screen travelUI  ################## Here the error!

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/houselocations.rpy", line 112, in script
    call screen travelUI
  File "renpy/common/000statements.rpy", line 670, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
TypeError: 'str' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/houselocations.rpy", line 112, in script
    call screen travelUI
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\ast.py", line 2259, in execute
    self.call("execute")
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\ast.py", line 2241, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\statements.py", line 342, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 670, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\exports.py", line 3347, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\ui.py", line 299, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\display\core.py", line 3582, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\display\core.py", line 3976, in interact_core
    trans = instantiate_transition(None, old_root, layers_root)
  File "C:\Users\bregl\Downloads\renpy-8.1.3\renpy-8.1.3-sdk\renpy\display\core.py", line 3922, in instantiate_transition
    trans = self.ongoing_transition[layer](
TypeError: 'str' object is not callable

Windows-10-10.0.22621 AMD64
Ren'Py 8.1.3.23091805
test 1.0
Tue Oct 31 15:40:37 2023


do not understand what I am doing wrong
[/CODE]
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
now subtract x1 from x2 and y1 from y2
eg store to work 2 - 20 =-17 and 1-20=-18
making sure to invert those two values if negative like in this case
add the values for total distance = 35
Your formula isn't wrong, but it apply to wargame maps with square cells. You pass in all vertical and horizontal cells, and therefore have to count them all.

But in the present case, it's not the formula that should be used, but the one everyone use as example to say that Math teach you nothing useful. Yeah, for once in your life you had to use Pythagoras theorem ;)

Therefore, the distance between those two locations is square root of ( (x2 - x1)² + (y2 - y1)² ), so 24.75.
For Ren'Py it would be:
Python:
init python:

    import math

    def distance( x1, x2, y1, y2 ):
        a = x2 - x1
        b = y2 - y1
        return math.srqt( a*a + b*b )
 
  • Haha
Reactions: GNVE

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
do not understand what I am doing wrong
Hmm, it's not you, it's me. Or, more precisely, it's me, then you.

I was already thinking about the rest, and messed the syntax for Show(). Then you misunderstood the reason why you got a "NameError" error.

It should be Show( "moveScreen", "home" ), sorry.
 

peterppp

Active Member
Mar 5, 2020
762
1,347
Don't do this! Doing this is silly but also a little fun (If I where to do a sandbox it might end in the game just because...).

But you could place all buildings on a grid (using excel if need be) and have different modes of travel be advantageous for different distances. (doing it in pseudo code because lazy :ROFLMAO:).
so something like:
home: 1,1
store: 2,1
park: 3,2
church: 4,7
school: 6,7
work: 19,19

now subtract x1 from x2 and y1 from y2
eg store to work 2 - 20 =-17 and 1-20=-18
making sure to invert those two values if negative like in this case
add the values for total distance = 35

now calculate travel time per mode of transport (time to start + (Distance / KMPH *60)
walking: 0 + (35 / 5 * 60) =420
Cycling 5 + (35 / 12 * 60) =300
Car 30 + (35 / 23 * 60) =121
PT 45 + (35 / 25 * 60) =129

but for home to the store it would look like
walking: 0 + (1 / 5 * 60) =12
Cycling 5 + (1 / 12 * 60) =10
Car 30 + (1 / 23 * 60) =32
PT 45 + (1 / 25 * 60) =47

(For the figures I quickly googled speeds for city traffic. the base time is the time it takes to get to your car or bike and park it at the destination. For the bus it assumes having to walk to the stop and having to wait a while.)
don't need to complicate things as much but a version of this is how he should do it instead of having that huge travelTime blob of locations and travel times.

SweetGames you already place the locations on the map with xalign and yalign. so place those values in variables and use the values to calculate the distance to travel. that way, everything will be calculated automatically when you place a location on the map. you never have to worry about it.

i disagree with anne on the math unless you use "fly like a bird" travel. this is travelling in a city and that generally means the streets are laid out in grids. you don't go in a straight line from point A to point B. that would fit better for travel cross country.
 

SweetGames

Newbie
Jan 1, 2023
33
4
With action ShowMenu( "moveScreen", "park" )I get this error

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 174, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 174, in <module>
    $ ui.interact()
  File "game/citynav.rpy", line 85, in execute
    screen moveScreen( where ):
  File "game/citynav.rpy", line 85, in execute
    screen moveScreen( where ):
  File "game/citynav.rpy", line 87, in execute
    vbox:
  File "game/citynav.rpy", line 88, in execute
    textbutton "walk":
  File "game/citynav.rpy", line 88, in keywords
    textbutton "walk":
  File "game/citynav.rpy", line 92, in <module>
    action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][0] ), Hide(), Jump( (where) + "Hub" ) ]
NameError: name 'currentTime' is not defined
 

GNVE

Active Member
Jul 20, 2018
724
1,184
you haven't yet defined the currentTime variable or made a typo in the name somewhere. (based on the error)

In this case this is the important bit of the error message :
NameError: name 'currentTime' is not defined
 
  • Like
Reactions: anne O'nymous

GNVE

Active Member
Jul 20, 2018
724
1,184
just like traveltime you need to set currentTime near the beginning:
Python:
define currentTime = 0
 

SweetGames

Newbie
Jan 1, 2023
33
4
Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 174, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 174, in <module>
    $ ui.interact()
  File "renpy/common/00action_data.rpy", line 75, in __call__
    _set_field(self.object, self.field, self.value, self.kind)
  File "renpy/common/00action_data.rpy", line 44, in _set_field
    fields, _, attr = name.rpartition(".")
AttributeError: 'int' object has no attribute 'rpartition'

sorry
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
Code:
    action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][0] ), Hide(), Jump( (where) + "Hub" ) ]
NameError: name 'currentTime' is not defined
You said that you "have already tried it on several ways but can't get it to work", but haven't provided information regarding the base code, therefore I used explicit, but generic, variable names that you are supposed to adapt to your current code.
Since you want a travel system, you surely already have an equivalent to the currentLocation variable. Yet I explicitly declared it because it is the core component of the system ; you need to works with the location before the move, and it's not necessarily implicit in the code.
But for currentTime, I haven't gone this far, expecting the name to be really explicit enough for you to replace it by whatever name you gave to the variable you use to keep track of the current time. Something that you already do, because you surely haven't decided to use a precise time value for the travel before you even implement the time system in the core mechanism of your game.


Code:
AttributeError: 'int' object has no attribute 'rpartition'
On me again... And, like for Show(), it's something that you should have been able to fix yourself by just reading the doc for SetVariable() ; doc that is on your computer, in the "doc" folder that come with Ren'Py SDK.

Should be SetVariable( "currentTime", currentTime + travelTime[currentLocation][where][0] ), with "currentTime" being replace by the name of the variable used to keep track of the current time value in the time system you already use.


*sigh*
For once I forgot to warn that I wrote the code on the fly, it had to be this time...