|
|
Line 1: |
Line 1: |
| ==Image help for my RPG==
| | I'm a noob 23214123543#@$%#!%T$#^@$%# |
| [[Image:RPGTut1.png|Picture is loading, please wait]]
| | ^342 |
| [[Image:RPGTut2.png|Picture is loading, please wait]]
| | 5$# |
| [[Image:RPGTut3.png|Picture is loading, please wait]]
| | ^%$#@ |
| [[Image:RPGTut4.png|Picture is loading, please wait]]
| |
|
| |
|
| | ^BY |
| | T4GV |
|
| |
|
| Scripting tutorial, Wiki format under construction
| | U all stink |
| --------------------------------------------------
| |
| ==Lesson-1==
| |
| --------------------------------
| |
| NOTE: In this tutorial we will be using the "print()" command. All this does is print whatever is in the brackets to the output bar
| |
| for example, print(1), makes the text "1" appear in the output bar
| |
| | |
| Also, if in a script you see this "-->" that means, "the outcome of this line is : ", and isn’t actually part of the script. It's a Comment, and wont actually
| |
| be part of your script, the computer just ignores it.
| |
| --------------------------------
| |
| | |
| Declaring and using variables
| |
| | |
| What is a variable?
| |
| A variable is a thing that stores a value. It could be any kind of value, such as a color, position, number, work/sentence etc... In programming,
| |
| Variables are a core aspect, most (if not all) scripts you make will have them.
| |
| | |
| How do you declare a variable in Lua?
| |
| Declaring variables in Lua is very easy, all you have to do it put the name of the variable, and then the assignment operator, and then the value
| |
| of the variable.
| |
| | |
| The only thing to note is that you variable name MUST NOT HAVE SPACES IN THEM, it will mess up your script if they do
| |
|
| |
| <pre>
| |
| a = 1
| |
| | |
| b = 3.14
| |
| | |
| c = 600
| |
| | |
| print(a) --> 1
| |
| | |
| print(b) --> 3.14
| |
| | |
| print(c) --> 600
| |
| </pre>
| |
| | |
| Now we move onto the types of data that a variable in Lua can store, there are 6 main types that I will discuss here.
| |
| | |
| ==Bool:==
| |
| --------------------
| |
| The Bool data type is the most simple one, it's either true or it's false, those are the only two things it can be
| |
| <pre>
| |
| a = false
| |
| | |
| print(a) --> false
| |
| | |
| a = true
| |
| | |
| print(a) --> true
| |
| </pre>
| |
| | |
| ==Number:==
| |
| ------------------
| |
| Also, a number, quite obvious as well. In Lua you don’t have to worry about the size of a number, like you do in C++, if it's a number it's a number.
| |
| <pre>
| |
| a = 1
| |
| print(a) --> 1
| |
| a = 3.14
| |
| print(a) --> 3.14
| |
| </pre>
| |
| also, you may see this
| |
| | |
| ##e+###
| |
| | |
| this just means exponential notation
| |
| | |
| 3.5e+004 = 3.5*10^4
| |
| | |
| ==String:==
| |
| -------------------
| |
| Now we get to the new stuff....
| |
| | |
| A string, is a "String of characters", it can be one anything from one single letter, to a whole sentence. To tell the computer you are using a string
| |
| The string must be enclosed in quotes
| |
| | |
| <pre>
| |
| myString = "Hello, World!"
| |
| | |
| print(myString) --> Hello, World!
| |
| | |
| print("hello!") --> Hello!
| |
| </pre>
| |
| The quotes aren’t actually part of the string, they just tell the computer what's in the quotes is a string.
| |
| | |
| ==Object:==
| |
| --------------------
| |
| As you already know, ROBLOX is build out of objects. Most of them being of the "Part" class, or bricks, but there are any others as well.
| |
| | |
| What an object Value does is store the memory location of tone of these objects, so that you can talk about it even if it doesn’t have a parent that you can access it through.
| |
| <pre>
| |
| a = game.Workspace.Part --we will discuss this next lesson
| |
| | |
| print(a) --> part
| |
| | |
| a:remove() --> removes the part
| |
| </pre>
| |
| | |
| Next we will look at the compound data types, these are ROBLOX specific, and thus must be called with the .new() command.
| |
| | |
| | |
| ==Vector3:==
| |
| ---------------------
| |
| A vector3 stores a position in space, based on z-y-x coordinates
| |
| also, vector3's have a ".magnitude" property in them, which tells you the length of the vector, from one corner, to the opposite corner.
| |
| <pre>
| |
| a = Vector3.new(1, 5, 3)
| |
| | |
| print(a) --> 1, 5, 3
| |
| | |
| print(a.x) --> 1
| |
| | |
| print(a.y) --> 5
| |
| | |
| print(a.z --> 3
| |
| | |
| print(a.magnitude) --> [I'm not sure, I'd have to calculate it, but it should be around 6.5]
| |
| </pre>
| |
| | |
| ==CFrame:==
| |
| -------------------------
| |
| CFrames store a position in space, and a rotation matrix, but they're quite complicated, and I will discuss them in a later lesson.
| |
| | |
| ==BrickColor:==
| |
| ------------------------
| |
| The brickcolor data type stores the color of a brick. brickcolor, for the purposes of this lesson they return a color based off of a number.
| |
| | |
| You can see a list of all of the codes, and what color they are, in your program files, inside the "res" folder, called "htmlcolortree"
| |
| <pre>
| |
| a = BrickColor.new(21)
| |
| | |
| print(a) --> Bright Red
| |
| | |
| a = BrickColor.new(23)
| |
| | |
| print(a) --> Bright Blue
| |
| </pre>
| |
| | |
| ==How do I use variables?==
| |
| You use variables in nearly all of the scripts you make as stated before, here is an example of a script that prints a number
| |
| <pre>
| |
| addendOne = 1
| |
| | |
| addendTwo = 5
| |
| | |
| sum = 0
| |
| | |
| sum = addendOne + addendTwo
| |
| | |
| print(sum) --> 6
| |
| </pre>
| |
| | |
| Try putting this in a script in Roblox... Go File>New, and select workspace, and insert a script into it. Then paste this into the script and Press
| |
| run (the green arrow at the top of the screen), and see what happens.
| |
| | |
| If you don’t have the output window open, then View>Output and it should appear at the bottom of the screen
| |
| | |
| When you run the text "6" should appear in the output.
| |
| | |
| you can try fiddling around some more if you want, and using the division "/", multiplication "*", and subtraction "-" symbols and seeing what happens
| |
| | |
| --------------------------
| |
| Now you know how to use basic variables, we can move on to How objects work in ROBLOX.
| |
| --------------------------
| |