Make a configurable travel helper
Keep your destination in a Lua settings file and request a path on demand.
This module lets you set a map and world position in a separate file. It only requests travel when you press its Go button. Choose coordinates from your own in-game location; the numbers below are placeholders.
This uses a module with a worker, the UI SDK, and the movement API. Install the bundled libraries with Download latest SDK before loading it.
Save Scripts/modules/my_travel/settings.lua:
return {
map_id = 1,
destination = { x = 100, y = 200, z = 300 },
arrival_radius = 150,
}Save Scripts/modules/my_travel/main.lua:
local settings = require("settings")
local ui_sdk = require("ui_sdk")
local traveling = false
local message = "Ready"
local function distance_to_destination(position)
local destination = settings.destination
local dx = position.x - destination.x
local dy = position.y - destination.y
local dz = position.z - destination.z
return math.sqrt(dx * dx + dy * dy + dz * dz)
end
local function check_progress()
local mapId, mapError = game.current_map_id()
local position, positionError = game.local_position()
if mapId == nil or position == nil then
traveling = false
message = mapError or positionError
elseif mapId ~= settings.map_id then
traveling = false
message = "Map changed"
elseif distance_to_destination(position) <= settings.arrival_radius then
traveling = false
message = "Destination reached"
end
end
function on_start()
local ok, err = script.start_worker(function()
while true do
if traveling then
check_progress()
end
script.sleep(500)
end
end)
if not ok then log.warn(err) end
end
function on_tick()
local ok, err = ui_sdk.window("my_travel", "My travel", {
x = 80, y = 120, width = 300, height = 180,
}, function(ui)
ui.text(message)
if ui.button("go", "Go") then
local mapId, mapError = game.current_map_id()
local position, positionError = game.local_position()
if mapId == nil or position == nil then
message = mapError or positionError
elseif mapId ~= settings.map_id then
message = "Open the configured map first"
else
local sent, sendError = game.request_path(
settings.destination.x,
settings.destination.y,
settings.destination.z)
if sent then
traveling = true
message = "Path requested"
else
message = sendError
end
end
end
end)
if not ok then log.warn(err) end
endSelect the module and press Load. After editing either file, press
Reload to import the saved settings again. game.request_path reports
whether the request was sent. The position check reports arrival only when
your character is within the configured radius; a path request itself does
not confirm movement or arrival. Use
game.path_destination() to read the
current path destination when one is available.
This example stays on the configured map and makes one request per button press. It does not retry failed requests, change maps, or prove that the route is reachable. If a game read fails, it stops tracking travel and shows the error. See errors and limits for handling unavailable character and world values.
Save a named travel configuration
A module can store its own serialized settings with the
private online profile methods.
For example, use the scope my_travel for this helper and save only the map,
destination, and arrival radius. Validate those values when downloading them,
save them locally, and keep traveling false until the user presses Go.
Match each on_http response to its request ID. A queued save is not a receipt,
and a loaded profile is not a travel command. The
Gathering guide shows a complete
named-config workflow in an existing module.