- 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
thank you
have already tried it on several ways but can't get it to work.
# 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"
[...]
[...]
screen travelUI():
for location in [ "home", "park", "store" ]:
imagebutton:
auto "{}_%.png".format( location)
action Show( moveScreen, location )
define travelTime = { "park": { "home": 20, "store": 15, "park": None },
"home": { "home": None, "store": 10, "park": 20},
[...] }
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" ) ]
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.For code I'm not the best so You probably want to follow AON. One optimization I could see is:
with the bus and car buttons just dividing the base time in 2 and 4 respectively (or whatever you want).Python:define travelTime = { "park": { "home": 20, "store": 15, "park": None }, "home": { "home": None, "store": 10, "park": 20}, [...] }
It works, but personally I would have used*please note I have not tested if this actually works in Ren'Py.Python:action [ SetVariable( currentTime, currentTime + round(travelTime[currentLocation][where] / 2) ), Hide(), Jump( where + "Hub" ) ]
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.I'm tempted to add that personally it's strict time in games that I tend to dislike.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.)
# 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
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.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
init python:
import math
def distance( x1, x2, y1, y2 ):
a = x2 - x1
b = y2 - y1
return math.srqt( a*a + b*b )
Hmm, it's not you, it's me. Or, more precisely, it's me, then you.do not understand what I am doing wrong
Show()
. Then you misunderstood the reason why you got a "NameError" error.Show( "moveScreen", "home" )
, sorry.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.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 ).
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.)
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
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
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.Code:action [ SetVariable( currentTime, currentTime + travelTime[currentLocation][where][0] ), Hide(), Jump( (where) + "Hub" ) ] NameError: name 'currentTime' is not defined
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.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.On me again... And, like forCode:AttributeError: 'int' object has no attribute 'rpartition'
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.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.