RunService

Your program's own run: its command-line arguments, its folder, its environment, a clean exit code and a last word before it stops.

require("@shotsystem/RunService") gives it; today use RunService doesn't resolve, so write the require line in a .shot file too. A run ends on Stop, on Quit(code), or once the body has returned and nothing live is left: no Page, Follow, timer, watched child or waiting thread. Then Stopping fires and everything the run opened closes. See running.

ShotInstanceservicenot creatablePrograms

A service: write use RunService.

Example

The run itselfLuau
--!strict
-- The run itself: its arguments, its working folder, the environment, Stopping and Quit.
local FileService = require("@shotsystem/FileService")
local RunService = require("@shotsystem/RunService")

print("arguments: " .. #RunService.Arguments)
FileService:WriteAsync("todo.txt", "buy milk")
local inFolder = FileService:ExistsAsync(RunService.ProjectFolder .. "/todo.txt")
print("a relative path lands in ProjectFolder: " .. tostring(inFolder))
FileService:RemoveAsync("todo.txt")
print("PATH is set: " .. tostring(RunService:GetEnv("PATH") ~= nil))

RunService.Stopping:Connect(function()
	print("Stopping fired")
end)
RunService:Quit(0)
print("never printed")
What it printedOutput
arguments: 0
a relative path lands in ProjectFolder: true
PATH is set: true
Stopping fired

Properties

NameTypeDefaultDescription
Arguments{ string }{}
read-only
What followed -- on the command line, as in shot run MyProject.shotsystem -- alpha beta; empty when nothing did.
ProjectFolderstringread-onlyThe folder holding the project file, with forward slashes; every relative path in the run starts there, whatever folder you ran from.

Methods

NameArgumentsReturnsDescription
GetEnv(name: string)string?The value of an environment variable of the run's process, or nil when it isn't set.
Quit(code: number?)()Stops the run, Stopping's callbacks first, and ends it with code, 0 when nil; it never returns.

Events

NamePassesDescription
Stopping()Fires as the run stops, by Quit, Stop or its natural end; its callbacks get up to 3 seconds together before the rest closes.
From ShotInstance 33