#Understanding Parameters

64 messages · Page 1 of 1 (latest)

open granite
#

Why does the function assume that the parameters value is the part that touches it. I don't understand the logic and don't see why it can't be anything else?

ocean helm
open granite
#

Ye, but why does it assume the same for normal functions too.

ocean helm
toxic kelp
#

Word

ocean helm
toxic kelp
#

He should rlly add if conditions

#

If hit.parent then

#

Bc what if it was baseplate

#

Baseplate dont got parent

open granite
ocean helm
#

yeah

open granite
#

ohh, does that mean its also possible to just write normal functions and use connect function when calling?

ocean helm
#

yes

open granite
#

alright, thanks man.

open granite
#

Because it checks if it has humanoid within before removing health.

ocean helm
#

you're probably printing what's touching it out of that if statement

#

I assume

open granite
#

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.

ocean helm
dark rapids
toxic kelp
#

Word

open granite
#

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

fair spearBOT
#

studio** You are now Level 2! **studio

toxic kelp
#

Wanna see my game?

dark rapids
toxic kelp
#

Pvp and rng

#

With quest

#

Interested in trying im still working on it

dark rapids
toxic kelp
#

Dont have

#

Also it has trading system made by me

open granite
#

send game

dark rapids
#

yea, send test server

toxic kelp
#

Let me send video

#

I script it all

#

@dark rapids

open granite
#

animations are pretty cool

toxic kelp
#

Its free bc i cant animate

dark rapids
fair spearBOT
#

studio** You are now Level 13! **studio

dark rapids
#

it seems far from the final product, keep it up

#

but those guis are 2017 roblox not gonna lie

dim needle
#

orienting my head 90* so i can view this video

toxic kelp
#

Uis are free idk how to design good ui

#

The ui style is free

vale wave
#

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

timber oxide
#

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.

open granite
open granite
dark rapids
# open granite 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
open granite
#

thx.

dark rapids