Scripting: Difference between revisions
>XLEGOx Added "spawn(f)" to global functions |
>XLEGOx Added "spawn(f)" to global functions |
(No difference)
|
Revision as of 04:39, 14 August 2010
This article is a portal for Roblox scripting and related articles.
Lua Programming Language
Roblox uses Lua 5.1, a concise and efficient scripting language used in games and embedded systems. Lua gives users the ability to create customized content beyond bricks, such as tools, weapons, vehicles, enhanced gameplay, and much more.
Tutorials
The Roblox Wiki offers many tutorials for learning Lua.
Environments and Libraries
An environment can be described as a place where variables, functions, etc live. Each script has its own environment.
A library is a group of functions that can be used to make scripting easier. For security purposes, some functions have been removed from Roblox to prevent access to system resources.
ROBLOX loads the coroutine, string, table, math, and basic function libraries.
Math
One important feature that nearly all programming languages use is math. For more information, and usage, read the following articles:
- Basic math
- Variables
- Conditional statements
- Random numbers
- How To Increase and Decrease Vector3 Values
Types
All values in Lua have their own type. These values can be stored in variables, passed as arguments to other functions, and returned as results.
Basic Types
Every value in Lua will be one of these types:
Roblox-Defined Types
These are special types created by and available only in Roblox.
- Vector3 -- Represents 3-dimensional coordinates. These are used for things like a brick's size or position.
- CFrame -- Holds a position and a rotation. These define the rotation of bricks.
- Color3 -- Makes colors using an RGB format.
- BrickColor -- Defines a specific color for bricks.
Global Functions
Roblox defines the following global variables:
game
is the DataModel object that is the root of the tree for a Place.workspace
is the Workspace object that is a child of the DataModel.script
is the Script object that defines the script. (not applicable for the Command toolbar)print()
echoes each argument to the Output panel.time()
returns the current game time in seconds. (NOTE: THis function is scheduled for an upcoming release)wait(t)
yields the current thread after "t" seconds have elapsed. If t is not specified, then it yields for a very short period of time. The function returns 2 values: The elapsed time and the current game time.delay(t,f)
Asynchronously executes function "f" after "t" seconds have elapsed. The function "f" is called with 2 arguments: The elapsed time and the current game time.spawn(f)
Same asdelay(t,f)
but with 0 wait time. Necessary sincedelay(0,f)
actually waits the minimum wait time of 1 frame, whereas spawn has no wait.
Roblox Objects
Objects are what make Roblox work. Everything seen in-game is an object, as well as everything visible in the Explorer panel. All Objects have Properties, Functions and Events.
Common Mistakes
The slightest misspelling, or even incorrect capitalization will result in your script failing to work. REMEMBER: Look at the Output to check for errors. If this doesn't help, back-track and make sure everything is perfect. If you think there is a problem, or you need help in general, request help on the Forum.
See Common Scripting Mistakes and Debugging. For more help, see the 'See Also' section at the bottom of the page.
See Also
In the beginning:...
- Your first script
- Basic Scripting
- Explaining Scripts
- Loops
- How To Increase and Decrease Vector3 Values
- In-Depth Scripting Guide
Scripting Tutorials and Articles:
- Commands
- Intro to Scripting: Make a Healing Potion
- In-Depth Scripting Guide
- Intro to Scripting: Make an Invisibility Tool
- Teleportation
- How to make lava
- How to Make Weapon Giving Teleporters
- How Do I Make Morphs?
- How to Create a Black Hole
- How to Make Conveyor Belts
- How to Make a Plane
- How to make circles
- How to make a spiral staircase
- How to make a double helix
General Information:
- Random numbers
- Commands
- Conditional statements
- Variables
- Flowcharts
- Generic for
- Bool
- String
- Flowcharts
- Linked lists
- Functions
- Tables
Support: