Function Dump/Roblox Specific Functions: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Legend26
Saw some people having no idea what the new security error was, so I clarified it here.
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">"
 
(34 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Map|[[Function Dump]]|[[Function Dump/Roblox Specific Functions|Roblox Specific Functions]]}}
{{Map|Function Dump}}


== Unlocked Functions ==  
== Unlocked Functions ==  
Line 9: Line 9:


{{Example|
{{Example|
<pre>
{{code and output|code=
function returntime(delay, gametime)
function returntime(timewaited, gametime)
   print("The delay was " .. delay)
   print("The delay time was " .. timewaited)
   print("The game time is " .. gametime)
   print("The game time is " .. gametime)
end
end


Delay(4, returntime)
Delay(4, returntime)
</pre>


Will result in:
|output=
<pre>
The delay time was 4.0257607937525
The delay was 4.0257607937525
The game time is 61.028665867139
The game time is 61.028665867139
</pre>
}}
}}
}}


===LoadRobloxLibrary([[String]] ''libraryName'')===
===LoadLibrary([[String]] ''libraryName'')===
Returns a library, 'libraryName' if it exists.  Else, it returns nil and an error message for use with the assert function.  Its a sort of copy of LoadLibrary except LoadRobloxLibrary can be used by anyone.
Returns a library, 'libraryName' if it exists.  Else, it returns nil and an error message for use with the assert function.  LoadLibrary can be used by anyone.


{{Example|
{{Example|
<pre>
{{code and output|code=
local lib=assert(LoadRobloxLibrary("RbxGui"))
local lib=assert(LoadLibrary("RbxGui"))
print(lib)
print(lib)
local lib2=assert(LoadRobloxLibrary("InexistantLibrary"))
local lib2=assert(LoadLibrary("InexistantLibrary"))
print(lib2)
print(lib2)
--> errors "Unknown library InexistantLibrary" because of assert
|output=
</pre>
Unknown library InexistantLibrary
}}
}}
}}
<!--
<!--
Line 76: Line 75:
Echos the security level of the current thread, and the last argument passed in, if supplied.
Echos the security level of the current thread, and the last argument passed in, if supplied.
{{Example|
{{Example|
<pre>
{{code and output|code=
printidentity()
printidentity()
</pre>
|output=
Will result in:
<pre>
Current identity is 2
Current identity is 2
</pre>
}}
-----
-----
<pre>
{{code and output|code=
printidentity(1, 5)
printidentity(1, 5)
</pre>
|output=
Will result in:
<pre>
5 2
5 2
</pre>
}}
}}
}}


Line 98: Line 93:


{{Example|
{{Example|
<pre>
{{code and output|code=
function returntime(delay, gametime)
function returntime(delay, gametime)
   print("The delay was " .. delay)
   print("The delay was " .. delay)
Line 105: Line 100:


Spawn(returntime)
Spawn(returntime)
</pre>
|output=
 
Will result in:
<pre>
The delay was 0.038302775910779  
The delay was 0.038302775910779  
The game time is 61.028665867139
The game time is 61.028665867139
</pre>
}}
}}
}}


===tick()===  
===tick()===  


Returns the time in [http://en.wikipedia.org/wiki/Unix_time UNIX time], which is the number of seconds since the Unix epoch, January 1st, 1970. This time advances without game running, network synchronization, or wait().  Using ''tick()'' in a [[LocalScript]] may result in a differrent number that if you were to use it in a [[Script]], which will fetch a user's computer time.
Returns the time in [http://en.wikipedia.org/wiki/Unix_time UNIX time], which is the number of seconds since the Unix epoch, January 1st, 1970. This time advances without game running, network synchronization, or wait().  Using ''tick()'' in a [[LocalScript]] may result in a different number that if you were to use it in a [[Script]] because using it in a LocalScript will fetch the user's current time while using it in a Script will fetch the server's current time.
''tick()'' is very accurate. Because of its high accuracy, it can be used to measure the time a certain function takes to execute by calling it before and after an operation has been done, then finding the difference.
''tick()'' is very accurate. Because of its high accuracy, it can be used to measure the time a certain function takes to execute by calling it before and after an operation has been done, then finding the difference.


{{Example|
{{Example|
<pre>
<syntaxhighlight lang="lua">
print( math.floor( tick() / (60 * 60 * 24) ) )
print( math.floor( tick() / (60 * 60 * 24) ) )
</pre>
</syntaxhighlight>


Results in how many days have passed since January 1, 1970.
Results in how many days have passed since January 1, 1970.
Line 128: Line 120:


{{Example|
{{Example|
<pre>
<syntaxhighlight lang="lua">
now = tick()
local now = tick()
a = 50
local part = Instance.new("Part")
b = 250
local later = tick()
c = a + b
later = tick()
print(later - now)
print(later - now)
</pre>
</syntaxhighlight>


Results in how many seconds it took to fetch a and b, to add them together, and to store them to c.}}
Results in how many seconds it took to create a new part in the Workspace.}}
<br>
<br>
<p style="text-align:right;"><b>More information on tick can be found [[Time_Management|here]]</b></p>
<p style="text-align:right;"><b>More information on tick can be found [[Time_Management|here]]</b></p>
Line 147: Line 137:
{{Example|
{{Example|
Start your place and let it run for a little while. In the [[Command Line]] type:
Start your place and let it run for a little while. In the [[Command Line]] type:
<pre>
<syntaxhighlight lang="lua">
print(time())
print(time())
</pre>
</syntaxhighlight>
Will result in some number, indicating how many seconds the game has been running for.
Will result in some number, indicating how many seconds the game has been running for.
}}
}}
Line 157: Line 147:


{{Example|
{{Example|
<pre>
<syntaxhighlight lang="lua">
print(version())
print(version())
</pre>
</syntaxhighlight>
Will result in a string that represents the current version of your roblox client. Formatted as <code>''x''.''x''.''x''.''x''</code>
Will result in a string that represents the current version of your roblox client. Formatted as {{`|''x''.''x''.''x''.''x''}}
}}
}}


Line 168: Line 158:


{{Example|
{{Example|
<pre>
{{code and output|code=
print(Wait(1))
print(Wait(1))
</pre>
|output=
Will result in:
<pre>
1.004991560393 566.78806415454
1.004991560393 566.78806415454
</pre>
}}
}}
}}


Line 180: Line 168:
== Locked Functions ==
== Locked Functions ==
These are functions that are used by the game to protect it, its clients, and its clients' computers.  Using them will cause the error 'Unknown exception' unless you are using the [[Command Bar]] or a [[CoreScript]] which have higher security levels than normal or local scripts.
These are functions that are used by the game to protect it, its clients, and its clients' computers.  Using them will cause the error 'Unknown exception' unless you are using the [[Command Bar]] or a [[CoreScript]] which have higher security levels than normal or local scripts.
===PluginManager()===
Returns the [[PluginManager]] object that plugins can use to create a [[Plugin]] object.
{{Example|
{{code and output|code=
--In a Plugin:
print(PluginManager())
|output=
PluginManager
}}
}}


===crash__()===
===crash__()===
Line 185: Line 186:
Crashes the game.  This is used by the game when it can no longer function correctly.  You can run it in your [[Command Bar]] but make sure you save your work prior to that.
Crashes the game.  This is used by the game when it can no longer function correctly.  You can run it in your [[Command Bar]] but make sure you save your work prior to that.


{{Example|If using the [[Command Bar]] or a [[CoreScript]]...<pre>
{{Example|If using the [[Command Bar]] or a [[CoreScript]]...<syntaxhighlight lang="lua">
crash__() --> crashes the game</pre>
crash__() --> crashes the game</syntaxhighlight>
If using a [[Script]] or [[LocalScript]]...<pre>
If using a [[Script]] or [[LocalScript]]...<syntaxhighlight lang="lua">
crash__() --> Unknown exception</pre>}}
crash__() --> Unknown exception</syntaxhighlight>}}


===LoadLibrary([[String]] ''libraryName'')===
===LoadRobloxLibrary([[String]] ''libraryName'')===
Returns a developer library, 'libraryName' if it exists.  Else, it returns nil and an error message for use with the assert function.  Its a sort of copy of LoadRobloxLibrary except LoadLibrary is restricted for Roblox developers only.
Returns a developer library, 'libraryName' if it exists.  Else, it returns nil and an error message for use with the assert function.  LoadRobloxLibrary is restricted for Roblox developers only.


{{Example|
{{Example|
<pre>
{{code and output|code=
local lib=assert(LoadLibrary("RbxGui"))
local lib=assert(LoadRobloxLibrary("RbxGui"))
print(lib)
print(lib)
local lib2=assert(LoadLibrary("InexistantLibrary"))
local lib2=assert(LoadRobloxLibrary("InexistantLibrary"))
print(lib2)
print(lib2)
--> errors "Unknown library InexistantLibrary" because of assert
|output=
</pre>
RbxGui
Unknown library InexistantLibrary
}}
}}
}}


Line 215: Line 218:
===Stats() or stats()===
===Stats() or stats()===


Returns the Client's [[Stats]] object. The [[Stats]] it returns are the ones you see on you screen when you press CTRL+F1 or CTRL+F2 in a game.
Returns the Client's [[Stats]] object. The [[Stats]] it returns are the ones you see on you screen when you press {{key press|Ctrl|F1}} or {{key press|Ctrl|F2}} in a game.


{{Example|
{{Example|

Latest revision as of 05:01, 27 April 2023

Unlocked Functions

These functions, methods and otherwise were added to Lua by the developers to make scripting easier and more powerful. These may include functions for specific objects, such as Vector3 or CFrame classes. They are listed here as well as on the Scripting page for easier reference.

Delay(Float t, Function f) or delay(Float t, Function f)

Executes function "f" after "t" seconds have elapse. The function "f" is called with 2 arguments: The elapsed time and the current game time.

Example
function returntime(timewaited, gametime)
   print("The delay time was " .. timewaited)
   print("The game time is " .. gametime)
end

Delay(4, returntime)

The delay time was 4.0257607937525

The game time is 61.028665867139


LoadLibrary(String libraryName)

Returns a library, 'libraryName' if it exists. Else, it returns nil and an error message for use with the assert function. LoadLibrary can be used by anyone.

Example
local lib=assert(LoadLibrary("RbxGui"))
print(lib)
local lib2=assert(LoadLibrary("InexistantLibrary"))
print(lib2)
Unknown library InexistantLibrary


printidentity(v, ···)

Echos the security level of the current thread, and the last argument passed in, if supplied.

Example
printidentity()
Current identity is 2

printidentity(1, 5)
5 2


Spawn(Function f)

Executes function "f" after thread next yields. The function "f" is called with 2 arguments: The elapsed time and the current game time.

Example
function returntime(delay, gametime)
   print("The delay was " .. delay)
   print("The game time is " .. gametime)
end

Spawn(returntime)

The delay was 0.038302775910779

The game time is 61.028665867139


tick()

Returns the time in UNIX time, which is the number of seconds since the Unix epoch, January 1st, 1970. This time advances without game running, network synchronization, or wait(). Using tick() in a LocalScript may result in a different number that if you were to use it in a Script because using it in a LocalScript will fetch the user's current time while using it in a Script will fetch the server's current time. tick() is very accurate. Because of its high accuracy, it can be used to measure the time a certain function takes to execute by calling it before and after an operation has been done, then finding the difference.

Example
print( math.floor( tick() / (60 * 60 * 24) ) )

Results in how many days have passed since January 1, 1970.


Example
local now = tick()
local part = Instance.new("Part")
local later = tick()
print(later - now)
Results in how many seconds it took to create a new part in the Workspace.


More information on tick can be found here

time()

Returns returns the current game time in seconds. Game time only updates during wait() and must be synchronized across network.

Example

Start your place and let it run for a little while. In the Command Line type:

print(time())

Will result in some number, indicating how many seconds the game has been running for.


version() or Version()

Returns Roblox's current version.

Example
print(version())

Will result in a string that represents the current version of your roblox client. Formatted as x.x.x.x


Wait(Float t) or wait(Float t)

Yields the current thread until "t" seconds have elapsed. If t is not specified, then it yields for a very short period of time (usually close to 1/30th of a second). The function returns 2 values: The elapsed time and the current game time.

Example
print(Wait(1))
1.004991560393 566.78806415454


Locked Functions

These are functions that are used by the game to protect it, its clients, and its clients' computers. Using them will cause the error 'Unknown exception' unless you are using the Command Bar or a CoreScript which have higher security levels than normal or local scripts.

PluginManager()

Returns the PluginManager object that plugins can use to create a Plugin object.

Example
--In a Plugin:
print(PluginManager())
PluginManager


crash__()

Crashes the game. This is used by the game when it can no longer function correctly. You can run it in your Command Bar but make sure you save your work prior to that.

Example
If using the Command Bar or a CoreScript...
crash__() --> crashes the game
If using a Script or LocalScript...
crash__() --> Unknown exception


LoadRobloxLibrary(String libraryName)

Returns a developer library, 'libraryName' if it exists. Else, it returns nil and an error message for use with the assert function. LoadRobloxLibrary is restricted for Roblox developers only.

Example
local lib=assert(LoadRobloxLibrary("RbxGui"))
print(lib)
local lib2=assert(LoadRobloxLibrary("InexistantLibrary"))
print(lib2)

RbxGui

Unknown library InexistantLibrary


settings()

Returns the Client's Global Settings object. The Global Settings this returns are the exact same as the settings you see when you go to Tools > Settings.

Example

If you're using the Command Bar or a CoreScript...

print( settings() ) --> Global Settings

If you're using a Script or a LocalScript...

print( settings() ) --> Unknown exception


Stats() or stats()

Returns the Client's Stats object. The Stats it returns are the ones you see on you screen when you press Ctrl+F1 or Ctrl+F2 in a game.

Example
If you're using the Command Bar or a CoreScript...
print( stats() ) --> Stats
print( stats() == game.Stats ) --> true
If you're using a Script or a LocalScript...
print( stats() ) --> Unknown exception
print( stats() == game.Stats ) --> Unknown exception


UserSettings()

Returns the Client's GlobalBasicSettings object. The GlobalSettings this returns are edited when you use the Control Editor to change your controls.

Example
If you're using the Command Bar or a CoreScript...
print( UserSettings().className == "GlobalBasicSettings" ) --> true
If you're using a Script or a LocalScript...
print( UserSettings().className == "GlobalBasicSettings" ) --> Unknown exception