|
If you're new to scripting, I highly recommend you look at this before you come here: http://www.roblox.com/Forum/ShowPost.aspx?PostID=66433584
We all know the basics, right? Yes, you do, but how can we do things to bricks and games if all we know we can do to them is destroy them and locate them?
Before we step into methods and functions, I'd just like to teach you a little about the 'local' feature before we move on.
----
If you don't use local, just remember your hands will be very sore after you make a script. Here is an example.
~
game.Workspace.jameswizard8.Head (Do a bunch of stuff)
game.Workspace.jameswizard8.Head (Do a bunch of stuff).
~
Of course, you could use copy and paste, but there is a more simple solution which will save you a couple of more minutes when making longer scripts. Let's say you wanted to refer to your head several times in a script. All we need to do is this:
~
local head = game.Workspace.jameswizard8.Head
~
Now, when we make our script, we can make our script much more simple. Example.
~
head (Do a bunch of stuff)
head (Do a bunch of stuff).
~
----
Now, let's move on to functions and methods. Functions are used to fire an event or do something when an event happens. An example is, let's say you're just walking around and you tap a small purple brick. The script inside this brick is using a function to detect you just touched it and is now executing an event. Suddenly, a GUI pops up that says "Hi!"
For a full list of methods and functions, go to ROBLOX Studio, then go to Help, then open up the Object Browser. There, you can find a full list of already-made functions and methods and properties (we'll learn about these shortly).
"BU, BU, BUT NONE OF THESE FUNCTIONS I R WANT I WANNA MAKE A FUNCTION DAT MAKES MESSAGES ON DAH SCREEN!"
That's simple. With our new knowledge of this 'local' we speak of, we can make what you want.
----
So, you want to make a function that makes a message? It's pretty simple actually, this is what you do. First, we have find out how to actually create a message.
~
local message = Instance.new('Message', Workspace)
~
"WAIT WUT BU HOW DID U-"
I know, I find it confusing how it creates messages, also, but we'll learn how to later. Now, we have to adjust the properties of this message. In this case, the text.
~
message.Text = text
~
"But I don't want it to say text! I'm just gonna adjust it so-"
No wait, leave it like that. We'll need to so we can edit the function to change the text later on.
Now we need to tell the script to wait, then remove the message.
~
wait(5)
message:Destroy()
~
This is our full script:
~
local message = Instance.new('Message', Workspace)
message.Text = "text"
wait(5)
message:Destroy()
~
We're almost done! Now, we just need a function name.
~
function messageCreation(text)
~
That's perfect! You can name the function anything, but don't remove the 'text' between the brackets, or else the entire script will break. Now, we just put our brand new function together, and we can use it! Overall:
~
function messageCreation(text)
local message = Instance.new('Message', Workspace)
message.Text = text
end
~
Now that we've done this, we can use this to create epic scripts, without having to spend long times making the same script over and over again!
~
function messageCreate(text)
local message = Instance.new('Message', Workspace)
message.Text = text
wait(5)
message:Destroy()
end
messageCreate("Hi")
--This script will make a message that says "Hi!" and remove it after 5 seconds
~
We're done!
----
That probably heated your brain up and you probably had to read it twice to understand, but you did it! You created a function!
"Now I wanna make a method!"
Methods are more advanced, so we'll learn those later on. But congratulations! You can now make even better scripts!
~★That, sir, is why we live in a world full of morons★~ |