Hey /prog/ at school we have to do some procedural writing activity, I decided to do Lua, you guys think this is a good TUTORIAL for BEGINNERS, and people with 0% experience with coding? inb4 ur spelling is shit
Commands:
= math.pi –Will print first 14 digits of pie.
= math.random(1,100) –Makes a random number gen.
a = 1
b = 2
= a+b
print(_VERSION)
+: addition
-: subtraction
*: multiplication
/: float division –(Standard Division.)
//: floor division
%: modulo –(Remainder.)
^: exponentiation –(To the power of)
-: unary minus
==:equality
~=:inequality
<:less than
>:greater than
<=:less or equal
>=:greater or equal
random = math.random(0,100)
print(random)
–This prints a valid point.
–Where as.
F = math.random(0,100)
print(f)
–Will have an error.
Introduction: Lua, what is it? Well you see Lua is a coding language, what is code? Code is what you use, to communicate with your computer. Lua is a lightweight addon to C. So where is it used? Lua has been used to make such applications and games as:
Adobe Photoshop Lightroom uses Lua for its user interface.
Cheat Engine, a memory editor/debugger, enables Lua scripts to be embedded in its "cheat table" files, and even includes a GUI designer.
Damn Small Linux uses Lua to provide desktop-friendly interfaces for command-line utilities without sacrificing lots of disk space.
Games that use Lua include:
Angry Birds
Crysis
Dark Souls
Garry's Mod
S.T.A.L.K.E.R: Call of Pripyat
S.T.A.L.K.E.R: Clear Sky
S.T.A.L.K.E.R: Shawdow
Saints Row 2
Saints Row 4
Saint Row 3
SimCity 4
Star Wars: Battlefront
Star Wars: Battlefront 2
The Sims 2: Nightlife
World of Warcraft
So, why lua? Well you see Lua is relatively easy to learn, thus my reasoning.
Today your going to be doing math, and making your own calculator for calculating, probability, and calculate the circumference of a circle.
Alright Step one, here we go.
First step make sure your computer is on. I'm expecting to much of you already aren't I?
Second step connect to internet, via bottom right then, click on the desired WIFI host. (HWDCSB-guest)
Third step open up the terminal via, bottom right, then click on accessories, then LXTerminal.
Forth step type in the terminal. “sudo apt-get install lua5.1” then allow it to run.
Fifth step type in “Lua5.1”
Sixth step Your lua interpreter has been opened, and your ready to code. What do we want to code though? Well today were going to make a calculator for doing probability and circumference of a circle.
Seventh step Alright, time to play around with your, interpreter. Type print(“Hello world”) congrats, you've joined the million of coders who have typed this first, as they begin to set out on there journey to create great things, like well this whole operating system was created by a coder.
Eighth step now that you've done that you can play around with some commands.
Example assign a to 1 via a=1 then do b=2 then do = a+b
Ninth step Now for our Probability calculator, we simple take any question involving probability, anyone got one? Question=false if question == false then print(“Alright lets do the chances of rolling a 5 on a 6 sided die”) end (do = math.random(0,6) if answer equals 5 then boom you won.)
Easy right?
Tenth step Now for that, circumference calculator. So say your trying to find the circumference of a circle with a 10cm long radius? Well this is easy actually. Simply do r = 10 then do = r/math.pi
your answer is? 3.18cm.
Eleventh step Alright guys now its your time to get to play around with your interpreter. What can you do? Well you can write some more calculations with those calculators you recently made, or you could try adding, a+b. Or simply just print some words, you can also use io.write“nil”
If you want to write something more complex you could do a couple of things
With if, then, or else.
And that is how to make a calculator for calculating circumference and probability, in Lua.