KodakKid3
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 2860 |
|
|
| 02 Sep 2013 08:01 PM |
So, I wrote a little script here:
function onTouch(part) script.Parent.Reflectance = 1 end
Which apparently won't work without this part on the end:
script.Parent.Touched:connect(onTouch)
What does that last line mean, and why do I need it? I thought the function onTouch worked fine on it's own. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2013 08:07 PM |
'function onTouch()' is simply a function. It does not do anything until it is called or connected to an event that meets its conditions.
'script.Parent.Touched:connect(onTouch)' would fire 'function onTouch' when script.Parent touches something. Therefore, 'function onTouch' doesn't have to be named that. It could be:
function onPie(part) script.Parent.Reflectance = 1 end
Which apparently won't work without this part on the end:
script.Parent.Touched:connect(onPie)
And it would work the same. |
|
|
| Report Abuse |
|
|
KodakKid3
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 2860 |
|
|
| 02 Sep 2013 08:11 PM |
So the Touched:Connect(onTouched) is what has the actual touch interest thing, and what calls the command?
And, it works find without one of those BasicObject Touchinterest things inside of it, why do some people use those? |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2013 08:13 PM |
| Just don't question it... Just do Whatever.Touched:connect(functionthing)... |
|
|
| Report Abuse |
|
|
KodakKid3
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 2860 |
|
|
| 02 Sep 2013 08:14 PM |
| Spleen, I'm questioning it because I want to actually understand how it works. |
|
|
| Report Abuse |
|
|
ToboboT
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
|
| 02 Sep 2013 08:18 PM |
Spleen you can't do something if you don't know what you are doing and Koda, your answer:
I always hated when scripters used these words that I don't know about and it would mess me up, so here's how I thought of it. The correct name for those lines are connectors. Because they connect to functions. But that confused me so I thought of scripts as guns.
The gun power and barrel is the functions and the code and the trigger is the connection line. So think on part.Touched:connect() as whenever that part is touched you pull a trigger which lights the gun powder named your function. Understand?
Thats the easiest way i could think of explaining it |
|
|
| Report Abuse |
|
|
KodakKid3
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 2860 |
|
|
| 02 Sep 2013 08:20 PM |
| Yeah, I think I get it. Thanks guys. |
|
|
| Report Abuse |
|
|
ToboboT
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
|
| 02 Sep 2013 08:22 PM |
| Anytime, and if you still don't understand PM I'll be glad to help! :) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2013 08:28 PM |
| Well geez... that's mean >-> |
|
|
| Report Abuse |
|
|
ToboboT
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
|
| 02 Sep 2013 08:29 PM |
| Nobody said anything mean. |
|
|
| Report Abuse |
|
|