Absolute beginner's guide to scripting: Difference between revisions

>JulienDethurens
>JulienDethurens
Line 70: Line 70:


==Setting Values in ROBLOX Lua==
==Setting Values in ROBLOX Lua==
What about changing values of objects in ROBLOX Lua? There is a way to do that, and it's more of the same. To set your health to zero (rather than going "''Off with your head!''") you need to set the Health property of your humanoid to zero. To set properties of objects, you use a period ('''.'''), the property name, an equals sign and the value.
What about changing values of objects in ROBLOX Lua? There is a way to do that, and it's more of the same. To set your health to zero (rather than going "''Off with your head!''") you need to set the Health property of your humanoid to zero. To set properties of objects, you use a period ('''.'''), the property's name, an equals sign and the value.


<pre>game.Workspace.jediknightkrazy.Humanoid.Health = 0</pre>
<code lua>game.Workspace.jediknightkrazy.Humanoid.Health = 0</code>


You will learn specifics about what is what in ROBLOX Lua later (such as "''What does the equals sign really do?''"). For now, you can consider yourself a really basic scripter that can call methods and change property values.
You will learn specifics about what is what in ROBLOX Lua later (such as "''What does the equals sign really do?''"). For now, you can consider yourself a really basic scripter that can call methods and change properties's values.


Protip: The Workspace is a special game service. Since it is used a lot in scripting, ROBLOX Lua has a built-in constant (just like '''game''') called '''workspace''' (lower-case) rather than '''game.Workspace'''. You'll learn about constants and variables later, but know that the Workspace is the only object in ROBLOX Lua that has it's own built in constant.
Protip: The Workspace is a special game service. Since it is used a lot in scripting, ROBLOX Lua has a built-in constant (just like '''game''') called '''Workspace''' rather than '''game.Workspace'''. You'll learn about constants and variables later, but know that the Workspace is the only object in ROBLOX Lua that has it's own built in constant. You can therefore do this:


<pre>workspace.jediknightkrazy.Humanoid.Health = 0</pre>
<code>Workspace.jediknightkrazy.Humanoid.Health = 0</code>


==Inserting a Script object==
==Inserting a Script object==
Anonymous user