Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 17 Sep 2012 02:46 AM |
Some basic stuff.
v = ('Scripting is ) b = ("legit.") print (v..b)
a = game.Workspace.Part a.Transparency = 0.9 or a.Anchored = false or a:remove()
print("hello guys")
print(2*4)
How am I doing so far? All of this in 15 minutes. Any tips?
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 17 Sep 2012 02:57 AM |
5 minutes later...
a = Instance.new("Part") a.Parent = Workspace a.Anchored = true a.Transparency = 0.8 a.Name = "Infocus"
Boolean is a fancy word for true or false
Amirite so far
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
XiJennyX
|
  |
| Joined: 29 Oct 2011 |
| Total Posts: 320 |
|
|
| 17 Sep 2012 06:23 AM |
Heres some more for you to learn,
when calling a new instance a = Instance.new("Part") put "local" infront of it so that it doesn't effect over parts of your script globally.
local a = Instance.new("Part") a.Parent = Workspace a.Anchored = true a.Transparency = 0.8 a.Name = "Infocus" |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 17 Sep 2012 06:51 AM |
"put "local" infront of it so that it doesn't effect over parts of your script globally."
no no no, you don't understand the difference between local and global variables. The difference isn't the same as localscripts (local, client side) and just scripts (global, server side).
The difference between a local variable and a global variable is that a local variable is only "accessible" within it's own scope.
Most people get by without knowing what a scope is, because most people don't know or bother learning this type of stuff, but a scope in Lua ends after an and and starts after one of the following:
a for loop, (for i = 1,10 do...) a while loop, (while (true) do...) a function, (function bar() ... end) an if statement, (if 5 + 5 == 10 then...)
This might not mean anything to you, but local variables are a decent way to keep code more clean but more importantly, keep the code efficient. Local variable are stored number wise, while global variables are accessed by the variable name. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 17 Sep 2012 07:02 AM |
Oops... Here's an example of how a local variable works (forgot to mention something about this in my last post):
function bar() local int = 0 string = "hello, world!" for i = 1,5 do print(int + i) if i == 2 then print(i + (2*10)) end local bool = false end print(int + 10) print(bool) end
print(int) print(string)
>1 /line: 5 >2 /line: 5 >20 /line: 7 >3 /line: 5 >4 /line: 5 >5 /line: 5 >10 /line: 11 >nil /line: 12 >nil /line: 15 >hello, world! /line: 16 |
|
|
| Report Abuse |
|
|
XiJennyX
|
  |
| Joined: 29 Oct 2011 |
| Total Posts: 320 |
|
|
| 17 Sep 2012 07:03 AM |
Lol Coincidence! I had just visited your shadow place :D |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 17 Sep 2012 11:52 PM |
._. back to learning
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 17 Sep 2012 11:57 PM |
| Good so far, you improved in 5 minutes. You'll be to where I am in no time. What I did was all the LuaLearners lessons by Slayer219 then just looked at other scripts. |
|
|
| Report Abuse |
|
|
|
| 17 Sep 2012 11:59 PM |
while wait(1) do -- loops over and over each second game.Workspace.Part.BrickColor = BrickColor.random() -- Sets brick's color random each second end --ends for the loop to loop over again |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 12:18 AM |
Thanks so much guys. Also yeah, lualearners is very informative. Im just having trouble with functions and events.
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
| |
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 12:25 AM |
function test () print ("hi") end test ()
I think thats right.
But
function onTouch (h) h:remove() end script.Parent: connect (h)
or idk what im doing
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 12:30 AM |
function onTouch(h) h:remove() end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 12:36 AM |
oh thx
also
"function onTouch(h) <- The part that touches the Parent ryt? amirite?
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 12:37 AM |
| The 'h' represents 'what' hit it, and at the bottom connection line, that is what needs to be hit for this script to trigger. |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 12:42 AM |
| If you need anymore help just PM me when ever I'm online. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 12:45 AM |
Also does
Instance.new("Message").Parent = Workspace and Instance.new("Message", game.Workspace) the same?
Because I am more familiar with ("Message").Parent = Workspace
Also I did use the local stuff, I just didnt include it here.
Btw, can somebody explain to me in simple english why we need a 'local' for scripts?
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 12:51 AM |
Im on Vector3 and colors.
I am getting functions and events through my head better than before.
Im just confused why we can name our own functions when there are the ROBLOX functions.
i.e.
function myfunction() <- It also says I can put anything in between the parenthesis (My script) end
so confused
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 12:58 AM |
function OnTouched(PartThatTouched) PartThatTouched:Destroy() end
PartA.Touched:connect(OnTouched)
How this works is like this:
When a PartA is touched, in order to mess with the part that touched PartA, we must assign a variable to what touched it. That's what PartThatTouched is for.
event Touched(Instance otherPart)
Instance otherPart means it needs a variable to be set to access it. So PartThatTouched becomes the variable to access what touched PartA.
Not the best explainer but I tried. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 01:01 AM |
I got the first part, but you lost on on event Touched.
Im assuming PartA is script.Parent
I c i c
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 01:03 AM |
It doesn't have to be script.Parent
script.Parent in most cases is a part and it works on parts.
You can do this:
Workspace.PartA.Touched:connect() Workspace.PartB.Touched:connect()
Instead of parenting the script inside the part. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 01:04 AM |
Yeah I know. Can you please try explaining the part I got lost with in your explanation? Im really eager.
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 01:11 AM |
function Name(Variable_For_Part_That_Touched) Variable_For_Part_That_Touched:Destroy() end
Workspace.PartA.Touched:connect(Name)
Now when PartA is touched Variable_For_Part_That_Touched is used to access the part that touched PartA.
Ex:
Noob touched part with his left leg. Variable_For_Part_That_Touched is used to access the noob's left leg.
Now using .Touched event doesn't require the parameter(which is Variable_For_Part_That_Touched), you only use it to do stuff to what touched it.
Since we give a parameter(in this case Variable_For_Part_That_Touched) it'll take place of the part that touched PartA, meaning we can access it using Variable_For_Part_That_Touched.
I give up on explaining.. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 18 Sep 2012 01:15 AM |
Haha, I kind of get it.
So on the connection line script...
game.Workspace.Part.Touched:connect (DOES MY FUNCTION/FUNCTION NAME GO HERE?)
■ ▬▬▬▬▬【Iɴғᴏᴄᴜs 】▬▬▬▬▬ ■ |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2012 01:17 AM |
Yes
function ANYNAME(Variable_For_Part_That_Touched) --Code end
Game.Workspace.Part.Touched:connect(FUNCTIONNAME) -- That'd be ANYNAME |
|
|
| Report Abuse |
|
|