skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 12:16 PM |
WHAT DOES IT MEAANNNNN!
Explain please. What is function? What is hit?
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 12:31 PM |
SADHASDA
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 12:52 PM |
Can someone please reply?
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
cart6157
|
  |
| Joined: 28 Feb 2009 |
| Total Posts: 2194 |
|
|
| 01 Dec 2013 01:05 PM |
Workspace.Part.Touched:connect(function(hit) print("This brick was just hit") hit.Transparency = 1 end) |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 01:06 PM |
@Cart
You didn't even answer my question!
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
cart6157
|
  |
| Joined: 28 Feb 2009 |
| Total Posts: 2194 |
|
|
| 01 Dec 2013 01:08 PM |
| It triggers when the something is touched, duuhh |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 01:09 PM |
@Cart
That still answers none of the questions asked.
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 01:10 PM |
http://wiki.roblox.com/index.php/Events http://wiki.roblox.com/index.php/Touched_(Event)
lrn2rblx.lua |
|
|
| Report Abuse |
|
|
cart6157
|
  |
| Joined: 28 Feb 2009 |
| Total Posts: 2194 |
|
|
| 01 Dec 2013 01:10 PM |
| Oooh, I know your situation. You have no idea of scripting. Here's a link for help: http://wiki.roblox.com/index.php/Absolute_beginner%27s_guide_to_scripting |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 01:12 PM |
>http://wiki.roblox.com/index.php/Absolute_beginner%27s_guide_to_scripting
Well, clearly you have no idea of the situation I am in. I am asking you why you would put a function there, when up until now I have been declaring functions. I am also wondering why there is a hit argument where the function is. But no, clearly you seem to have this idea that everyone who doesn't know everything humanly possible about Lua is a beginner. Wow.
And I thought you were here to help people. My mistake.
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 01:17 PM |
| No, if you don't know what this means, it means you are still a beginner. |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 01:19 PM |
| The reason they put (hit) was so they could call the object that was touched easier, than having to say "Workspace["Object Name"], and they put a function their so it the lines of script in the function would be triggered by the event of it being touched. |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 01:31 PM |
>No, if you don't know what this means, it means you are still a beginner
Um. That is wrong.
There are many ways to make a script that does the same thing. It is not unreasonable to believe that someone could go a long time scripting and not know what that means.
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 01 Dec 2013 01:41 PM |
Mother of nine gods. Here, OP, this is what it means: Scripts need ways of detecting things. Things happen in-game, and it stimulates a certain 'listener,' connected to a certain object, that waits for a certain thing to happen. Let us take an ordinary brick. Perhaps we wanted to make it an anti-gravity platform. A custom event could be created, such that when the player is within the upper bounds of the part, he or she becomes unaffected by gravity. We also need another event that can allow gravity to take hold of that character once again when he or she leaves the bounds of the part.
Now that you get the intuition, I shall add some formalism. Those 'listeners' are called events in Lua. They are connection-based entities that call a given operation when an assigned threshold is met. This operation is in the form of a function, or a variable defined as a block of code to execute when called. The most basic example of an event is Touched. Touched is not a function; it is an event. Allow me to extrapolate:
function touched(p) -- This is the operative function. 'touched' is a variable name, so it can be virtually anything, as long it doesn't start with a number, contains only alphanumeric characters (excluding the underscore). print(p.Name.. ' has touched the part!') end -- we add an end to end the scope of touched
Workspace.Part.Touched:connect(touched) -- this is the connection line
Events are connection-based, so we need to connect them to a function using the connect method. All BaseParts have the event Touched, and Touched has the method connect. The connect method takes a function as a parameter; meaning, we put the function or a variable representing a function inside of the parentheses when calling connect ('(function)'). So, what does this do? It simply prints the name of the part that has touched the part in Workspace called 'Part'. Now, can we do it differently? Certainly. We can also do it more efficiently this way. We can try defining the function NOT in a variable, but strictly inside of the connect method:
Workspace.Part.Touched:connect(function(p) -- Snap! I just defined a function inside of the connect method. print(p.Name.. ' has touched the part!') end) -- End the scope, also close our open parenthesis.
This is just a very quick, rudimentary explanation. I recommend my work-in-progress crash course: https://googledrive.com/host/0BygQW0Uq8-q0eFY0UWpfbmJqR3M/index.html |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 01:41 PM |
@Skyarex,
Actually, the knowledge that you've showed us proves yourself wrong. There's only one way to get the part that touched another part. That's with a parameter (The "hit" in that function). Yes, I admit, there are more complex ways to tell wether something hit another part using some positioning and stuff, but that's outright stupid for someone to write that much code.
There are two ways to write a function. Unanimous and a named function. A named function looks like this:
function myNamedFunction() end
Let's say we want myNamedFuntion to be fired when "myPart" was touched.
function myNamedFunction() end game.Workspace.myPart.Touched:connect(myNamedFunction())
Now, what I showed above was the connection line. What if we want to simplify the above code into one line?
game.Workspace.myPart.Touched:connect(function() end)
That is the exact same thing as the above 2 lines (Excluding the "ends"). Where would our "hit" parameter go?
Named function: function myNamedFunction(hit) end game.Workspace.myPart.Touched:connect(myNamedFunction())
Unanimous function: game.Workspace.myPart.Touched:connect(function(hit) end) |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 01 Dec 2013 01:44 PM |
http://wiki.roblox.com/index.php/Anonymous_Functions
Yay, researching things for yourself before making a new thread :D
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 01 Dec 2013 01:50 PM |
@BattleBlox, the anonymous function is a different way. Also, there is another way.
local isTouching = function(part1, part2) local x1, y1, z1 = part1.Position.x, part1.Position.y, part1.Position.z local x2, y2, z2 = part2.Position.x, part2.Position.y, part2.Position.z local w1, h1, d1 = part1.Size.x, part1.Size.y, part1.Size.z local w2, h2, d2 = part2.Size.x, part2.Size.y, part2.Size.z
return ( ((x1 <= x2)and (x2 <= x1 + w1)) or ((x2 <= x1) and (x1 <= x2 + w2)) ) and ( ((y1 <= y2)and (y2 <= y1 + h1)) or ((y2 <= y1) and (y1 <= y2 + h2)) ) and ( ((z1 <= z2)and (z2 <= z1 + d1)) or ((z2 <= xz) and (z1 <= z2 + d2)) ) end
while (wait()) do for _,v in pairs(Workspace:GetChildren()) do if (v:IsA('BasePart') and v.Name ~= 'Terrain') then if (isTouching(v, Workspace.Model.DesiredPart)) then print('Yes.') end end end end |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 01 Dec 2013 01:52 PM |
Jesus christ stop posting I get it!
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
transIate
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2699 |
|
| |
|