Globals | CraytaKit
Skip to main content

Globals

Functions

Function NameReturn TypeDescriptionTags
IsInSchedule()booleanReturns whether the function is executed inside a schedule or notNone
Wait(number time)numberWait for at least given time interval in seconds then resume execution, and return the exact time taken (which will be the next frame after time seconds)Schedule-Only
Wait()numberWait for the next frame, then resume execution
print(...)NoneStandard print function (same as Print), takes a comma separated list of arguments and prints out their string representation.None
Print(...)NoneStandard print function (same as print), takes a comma separated list of arguments and prints out their string representation.None
printf(...)NoneThis print function replaces instances of {1} in format with the first argument passed in, {2} with the second etc (same as Printf).None
Printf(...)NoneThis print function replaces instances of {1} in format with the first argument passed in, {2} with the second etc (same as printf).None
FormatString(string format, ...)stringFormat a string using either {1}, {2} as in Printf, etc or using named variables.None
GetWorld()WorldGet the World objectNone
IsClient()booleanReturn true if this script is running on the clientNone
IsServer()booleanReturn true if this script is running on the serverNone

Examples

IsInSchedule

function ExampleScript:PerformSchedule()
self:Schedule(function()
print(IsInSchedule()) -- prints true
end)
print(IsInSchedule()) -- prints false
end

Wait

function ExampleScript:PerformSchedule()
self:Schedule(function()
local dt = Wait() -- waits a single frame
print(dt) -- Prints the number of seconds since the last frame
end)
end
function ExampleScript:PerformSchedule()
self:Schedule(function()
local dt = Wait(10) -- waits 10 seconds
print(dt) -- Prints the number of seconds since the last frame
end)
end

print

function ExampleScript:Print()
Print("Hello, world!")
end

see: print

printf

function ExampleScript:Printf()
printf("Hello, {1}", "AJ") -- prints "Hello, AJ"
end

Printf

see: printf

FormatString

function ExampleScript:FormatString()
local formattedString = FormatString("Hello, {1}", "AJ")
print(formattedString) -- prints "Hello, AJ"
end

GetWorld

Gets the currently loaded World

function ExampleScript:GetWorld()
local world = GetWorld()
print(world.dayLenght) -- Prints the length of the world's day
end

IsClient

function ExampleScript:Init()
print(IsClient()) -- Returns false, since Init is run on the server
end

function ExampleScript:LocalInit()
print(IsClient()) -- Returns true, since LocalInit is run on a client
end

function ExampleScript:ClientInit()
print(IsClient()) -- Returns true, since ClientInit is run on all clients
end

IsServer

function ExampleScript:Init()
print(IsServer()) -- Returns true, since Init is run on the server
end

function ExampleScript:LocalInit()
print(IsServer()) -- Returns false, since LocalInit is run on a client
end

function ExampleScript:ClientInit()
print(IsServer()) -- Returns false, since ClientInit is run on all clients
end
© 2024 CraytaKit