#Understanding Parameters
64 messages · Page 1 of 1 (latest)
Well, the touch function has the part that touched it as its first parameter
Ye, but why does it assume the same for normal functions too.
In this case, the connect function will call the function, which is its first parameter, and set its first parameter as the part that has been touched.
Word
Imagine it like this: (Just an example)
function Connect(FunctionToBeCalled)
local hit = (Part that has been touched)
FunctionToBeCalled(hit)
end
He should rlly add if conditions
If hit.parent then
Bc what if it was baseplate
Baseplate dont got parent
Just go with the flow
Wait so it's because of how I call the function since in the last line it calls it with part.Touched:Conncect(damagePlayer) ?
yeah
ohh, does that mean its also possible to just write normal functions and use connect function when calling?
yes
alright, thanks man.
It only prints whatever touched it whenever it is not something that has a Humanoid within it.
Because it checks if it has humanoid within before removing health.
ye you are correct
afterwards it checks for humanoid before removing 10 health points
that way there will be no errors that i can think of, since everything else that makes contact with it besides humanoids will not be subtracted health, meanwhile humanoids will which there is no error for.
I'd do that a different way since it would not damage the next player that touches it when debounce is true
instead of task.wait(3), add an attribute to the player's character that determines the time it takes damage and use task.spawn() to task.wait so the script isn't held up and other players can take damage simultaneously.
Word
wow yeah i completely forgot that it disables it for other players aswell lol, thanks for mentioning it because its hard to notice when i am testing it all by myself in studio
** You are now Level 2! **
Wanna see my game?
what is it about?
show trailer
send game
yea, send test server
animations are pretty cool
it's alright
** You are now Level 13! **
it seems far from the final product, keep it up
but those guis are 2017 roblox not gonna lie
orienting my head 90* so i can view this video
Y'all explained this terribly
The function doesn't assume the parameter's value. RBXScriptSignal, the object that events in Roblox are built on, have a "Connect" method which is classified as a higher-order function (HOF). HOFs are described as a function that returns and/or accepts functions. A callback is a function whose execution is delegated to another. In this case, you're passing a function to BasePart.Touched:Connect, which will in turn store that function's "memory address" into an internal array. When the physics engine detects a collision between two parts, it will fire the event, in which the event will iterate over that internal array and asynchronously call each function with the respective arguments
This is how your function gets called and receives its value(s)
TL;DR: It is being called by the engine and being fed the anticipated argument; you're the one who has to conform to the data the engine will give you, using different parameters will not result in different behaviour. Consult the API reference of the event to determine what values it will provide the given callbacks
part.Touched returns an RBXScriptSignal, and using :Connect() on it returns an RBXScriptConnection. Whenever the part detects that something Touched it, it executes the part.Touched event. Any functions connected to that event will run. However, the game will also send a parameter to the function, the parameter being the Instance the part touched.
This applies to all types of events. Think about a RemoteEvent. You can tell it to pass values, and any functions connected to that RemoteEvent will receive those values.
Is there no way to make it so the Debounce only affects local players?
add a bool attribute
alright, im gonna learn what this is and see if i can implement it
function Perishable.FruitCalculation(basePart, FruitModel)
if basePart.Parent:FindFirstChild("Humanoid") and basePart.Parent:GetAttribute("Consume") ~= false then
basePart.Parent:SetAttribute("Consume", false)
task.spawn(function()
task.wait(0.25)
basePart.Parent:SetAttribute("Consume", true)
end)
local character = basePart.Parent
FruitAbility[FruitModel.Name](character, FruitModel)
end
end
oh so its basically like a on/off feature for all players
thx.
more or less, it simply prevents the code from running unless the attribute is intended bool value
