|
Post by Tag365 on Nov 8, 2014 16:57:54 GMT
--------------------------- --------Script 1--------- ---------------------------
-- Warning: This script requires the Draw Library.
-- Firstly, you should learn about functions. A function is a type of variable which can be called at any time in a script.
-- To call a function we add text to the script that reads like the line below. draw.setscreen(1)
-- The above function allows you to switch to the graphics screen.
-- As you can see above, there is a number between the ( ) symbols. This is to provide the correct argument value so we can switch to the draw screen.
-- To test this script, click the play button.
sys.sleep(math.huge) -- As you can see right here, the graphics screen is shown for an indefinite amount of time. -- However, this is because of the function on the above line (sys.sleep). If this function was not called then the graphics screen would show for a second then disappear quickly, as this is the end of the script. -- By the way, the argument sent to the sleep function is "math.huge", an infinte number. If it was a regular number the function would only sleep a while and then the script would end.
-- End of script.
|
|
|
Post by Tag365 on Nov 8, 2014 16:59:49 GMT
---Script 2---
-- Start of script. draw.setscreen(1)
-- Now while we are in the graphics screen we can draw items to the screen at will.
-- Firstly, you can clear the screen by calling draw.clear(). The argument you give to this function determines the new color of the screen. draw.clear(draw.lightgray)
-- We can draw a circle outline by calling this function below, draw.circle. draw.circle(48, 48, 18, draw.black)
-- That will draw a circle at 48 draw screen pixels away from the left, and 48 pixels from the top. If you changed the arguments this will draw somewhere else, x pixels away from the left, and y pixels away from the top.
-- like the clear function you can also set it to draw in a certain color.
-- We can also draw a rectangle by calling this function below. draw.rect(64, 64, 96, 80, draw.blue)
-- Remember you can switch the values of the arguments given to change where the rectangle will be drawn, and the color of the rectangle.
-- You can also draw a filled rectangle as well. Just use the function draw.fillrect instead of draw.rect. You can also do this with draw.triangle, draw.circle, and draw.ellipse. draw.fillrect(98, 64, 222, 128, draw.orange)
-- As said above, there are other functions to draw stuff to the screen. Try to figure out what these functions do. draw.line(24, 144, 128, 144, draw.purple) draw.triangle(33, 88, 99, 88, 66, 128, draw.green) draw.ellipse(244, 48, 270, 128, draw.red)
-- Now you know how to draw stuff to the screen.
sys.sleep(math.huge) -- End of script.
|
|
|
Post by Tag365 on Nov 8, 2014 17:01:05 GMT
---Script 3---
-- Start of script.
-- We said functions were a type of variable. Variables can be modified at any time when running a script.
-- There is more than one type of variable. Numbers, booleans, functions, strings, and tables are five of the seven types of variables.
-- Firstly, booleans are variables which are equal to true or false. Very simple.
-- To change a variable's value at runtime, use a line of text (or code) similar to the line below. NewBoolean1 = true
-- Now when we use the print function, which prints text to the output window, using the variable NewBoolean1, the value of the variable is printed. print(NewBoolean1)
-- The script prints the value of NewBoolean1. As we set it to be true, the value printed is true.
-- You should know what a number is. You should also know that in Lua scripts, you can use numbers that are negative (below zero), and also numbers that are between whole numbers.
-- NewNumber1 = 33.33 NewNumber2 = -2.9283 NewNumber3 = 3.124
-- You can also use mathmatics on numbers.
NewNumber4 = NewNumber1 + NewNumber2 NewNumber5 = 32 * (NewNumber1 - 33) + 1 NewNumber6 = ((75 * 326) / 733^2)*124
print(NewNumber4, NewNumber5, NewNumber6)
-- Another type of variable is the string, which is a string of characters (and also why it is called a string).
-- To create a string, enclose text in "", '', or [[ and ]]. String1 = "This is a string." String2 = 'This is also a string.' String3 = [[This is a multiline string.]]
-- You can combine strings by using "..". String4 = "This is a "..'combined string.' .. [[ The string is on more than one line.]]
print(String4)
-- You can make a function in two styles. Use custom functions when you need to reuse a sequence of operations in multiple locations in your script. NewFunction1 = function() print("This is a function.") end
function NewFunction2() print("This is NewFunction2.") end
NewFunction1() NewFunction2()
-- A table allows you to store keys and values in a single variable. The draw functions are in a table named "draw".
-- To make a table, use {}. You will use tables for other stuff as you learn more.
-- If you need to determine a variable's type, use the type function.
print(type(NewFunction2)) -- End of Script.
|
|
Atom
Junior Member
Posts: 81
|
Post by Atom on Nov 8, 2014 22:55:37 GMT
That's a great tutorial for beginners!
|
|