generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Club Houses » ROBLOX Talk
Home Search
 

Learning to Script?

Previous Thread :: Next Thread 
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
04 Oct 2011 07:38 PM
I hate the idea of calling this a "tutorial", because of what that generally means to Robloxians, that they're just going to jump in and be able to copy off the screen code, and see stuff happen.
Because that doesn't tell you how to do anything except read.
But, this IS a little bit like that.
Except none of this stuff is exceptionally amazing.

Scripting is translating- taking a thought that you have, and turning it into the Lua code that performs that operation.

"--" means you can ignore this if its the first time reading through. I suggest you read through it a second time, NOT ignoring these, then.

m = 5 + 8
This sets m to the evaluation of 5 + 8.

---Oh, and this is your first syntactic structure.
---The LEFT of the = is the 'variable'. Might be a property or just a name
---(like in this case, could be m, or matter, or m23409n or m134, etc)

(So this is the same as m = 13.)
You could also do, for example:
p = 5 + 8
m = p + p + 8
This would be the same as
m = 13 + 13 + 8
or
34.

Going back to
m = 5 + 8.
We said this "sets m to the evaluation of 5 + 8."
Let's look at it the other way:

You need to evaluate 5 + 8.
[translate into Lua]
m = 5 + 8

The entire process of learning Lua is how to translate ANYTHING into Lua.
Although that's really an accumulation of months and sometimes years of constant working with the language.


Most of the time, programs execute from the top to the bottom, moving down one line at a time.
Structures modify this order, though.
Simplest structure: if.

m = 5 + 8
if m == 12 then
k = 0
else
k = 5
end

First line executed:
m = 5 + 8. M is now 13.
Now you reach "if m == 12 then".
Look at the area between the "if" and "then" (this is what Lua looks at.)
m == 12.

---"==" is a "binary operator" which checks equality.
---This would be the same as typing 'true' if they are equal,
---or false if they were different. The others are ~= (not equal)
--->,>= (larger than, larger than or equal to, and same with smaller than [<])

m == 12 --> False.
So this condition is false.
This means you skip this next part of code (skipping to the "else", since it was false).
k = 5.
end (You're now OUT of the realm of that if statement. Resume to normal execution).

So if m was 12, k would be 0.
Otherwise, it would be 5.

Let's trace through that more carefully (#'d steps):
m = 5 + 8 --1.
if m == 12 then --2. --> (m==12) is false. --> Skip this part.
k = 0
else
k = 5 --3.
end --exiting structure.
--4.

The lines with the --'s were executed in order.
Well, this isn't that interesting, is it?
You can only tell the program to go down, which means it'll be very difficult to have any sort of complex behavior.

Introducing, while loops.
They work essentially the same way as 'if's, except that they repeat over and over, until the condition is false;

i = 0 --1.
while i < 3 do --2 --> 0 < 3 is true; 6. 1 < 3;
i = i + 1 --3.; 7.
a = i --4.; 8.
end --5. Go back up to while.; 9. go back;

(and repeats after 9 again until i == 3, so it's not true, and you get to the bottom.)

====================================================
Trouble understanding? The best way to learn is practice.
Take advantage of a line like
print(i)
in the above example.
This 'print's (outputs) the argument (the 'i') to the Output bar in Roblox.
====================================================

The above 'print' is another useful structural, called a 'function'.
Functions are passed 'argument's which are given between parenthesis.
The function can then take these arguments and use them as variables.

It simplifies complex code a lot by turning it into small, breakable parts.
However, it can also do completely unique things such as recursion and functional programming (which I won't discuss here at least for a while).

As stated above, you "call" or "invoke" a function by:

[functioname](5,8,m+n,37)

(Where the arguments are expressions. Note, that expressions can include functions!)

m = 5 + add(8,9)
for instance, is valid.
So is simply
add(8,9)
although this probably would accomplish very little as 'returning' the addition would never go anywhere.

You "define" a function, so that it can be called like this:

function [functionname](args [which are variable names separated by commas])
--Function contents, which operate just like a normal script.
end

A "return" in a function which "return" the value following it.
For instance...

function add(a,b)
return a + b
end

This is given to values, a, and b.
It evaluates 'a + b', and then 'return's' that statement, so that if I did
a = add(5,8)
it would 'return' 13, and a would be 13.

--End for now. I will add more later. Somewhat halfway through a thought.--
Report Abuse
Xdimensional is not online. Xdimensional
Joined: 06 Mar 2009
Total Posts: 12069
04 Oct 2011 07:40 PM
No.....lol.
Report Abuse
dawoofinater is not online. dawoofinater
Joined: 12 Sep 2008
Total Posts: 10657
04 Oct 2011 07:41 PM
thanks
Report Abuse
qn1 is not online. qn1
Joined: 12 Aug 2011
Total Posts: 8481
04 Oct 2011 07:42 PM
You were the guy that helped dignity test lighting stoof.
Report Abuse
billwiw is not online. billwiw
Joined: 03 Sep 2008
Total Posts: 2765
04 Oct 2011 07:44 PM
Scripting help, go to that forum.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Club Houses » ROBLOX Talk
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image