Absolute beginner's guide to scripting: Difference between revisions

Fixing
(More local function)
(Fixing)
 
(One intermediate revision by one other user not shown)
Line 51: Line 51:
Here's our starting command. It's what we want to happen, and it has been written in plain English.
Here's our starting command. It's what we want to happen, and it has been written in plain English.


<code>Remove USERNAME's head.</code>
<pre>Remove USERNAME's head.</pre>


Naturally, ROBLOX will not like that very much because it's in English! You have to figure out how to express what you want to happen in Lua code.
Naturally, ROBLOX will not like that very much because it's in English! You have to figure out how to express what you want to happen in Lua code.


<code>In game, find Workspace, find USERNAME, find his Head, and remove it.</code>
<pre>In game, find Workspace, find USERNAME, find his Head, and remove it.</pre>


'''game''' is the root of all things in your game. We need to "go down" the family tree and find the right brick to remove. To get an object that is a child of another object this, you use a period ('''.''') after the parent object, then the child object's name. Going through the family tree, we get this:
'''game''' is the root of all things in your game. We need to "go down" the family tree and find the right brick to remove. To get an object that is a child of another object this, you use a period ('''.''') after the parent object, then the child object's name. Going through the family tree, we get this:


<code>Delete game.Workspace.USERNAME.Head</code>
<pre>Delete game.Workspace.USERNAME.Head</pre>


This is almost a working ROBLOX Lua statement! Now, to actually remove the head, a '''method''' must be used. Methods are functions that do specific things in ROBLOX for you by '''calling''' them. Methods are functions of objects in ROBLOX Lua. To call a method on an object in Lua, you use a colon (''':''') after the object. You then state the name of the method, then two parenthesis with nothing in them. Methods and functions take '''arguments''', which are values given to the function to change how it works. The "Destroy" method takes no arguments, so we place the parenthesis there to show that there's nothing else we have to give to the Destroy method.
This is almost a working ROBLOX Lua statement! Now, to actually remove the head, a '''method''' must be used. Methods are functions that do specific things in ROBLOX for you by '''calling''' them. Methods are functions of objects in ROBLOX Lua. To call a method on an object in Lua, you use a colon (''':''') after the object. You then state the name of the method, then two parenthesis with nothing in them. Methods and functions take '''arguments''', which are values given to the function to change how it works. The "Destroy" method takes no arguments, so we place the parenthesis there to show that there's nothing else we have to give to the Destroy method.