Guide to event-based programming and why it's supreme

Cool and all, but why are the codeblocks so badly formatted?

Because Roblox won’t let me indent when making a post

while true do
    local parts = myPart:GetTouchingParts()

    if #parts > 0 then --//A part was found in the table returned, so we know something is touching our part
        workspace.Baseplate.BrickColor = BrickColor.Black()

        break
    end

    wait()
end

Doesn’t stop you from pressing space or using a tool such as

Just a suggestion because new programmers look at these and they should be written in proper code syntax as to ease readability.

That tool doesn’t work for me, and yeah it’s weird how you can’t use tab on here. I also don’t feel like spamming my space bar 10 times per line.

5 Likes

I’m a little confused by this, could you possibly show a code example of what you mean? Thanks!

1 Like

Is this right? According to the wiki, a BindableEvent can only be subscribed to by one script:

I couldn’t find any clarification of what “Subscription” means in this context, but I took it to mean a connection to the event, so you can only connect one function to a BindableEvent at a time

Ahem ahem. BindableEvents can be connected by unlimited scripts.

BindableFunctions only by one.

1 Like

yeah I tested it out and I could connect as many scripts as I wanted. do you know what it meant by the subscription limitation then?

Perhaps I didn’t do a great job of wording that.

Basically like, I’ve found it being better practice (for me personally) to put something like this within your ModuleScript’s environment:

function myModule:Init()

someBindableEvent.Event:Connect(function()
--//Do stuff within this module
end)
end

Versus explicitly running a bunch of module methods when an event occurs:

--//Regular script

someBindableEvent.Event:Connect(function()
moduleA:Cleanup()
moduleB:Cleanup()
moduleC:Cleanup()
end)

Both work obviously, I just personally prefer the first option because it feels like you have more control.

1 Like

Probably just how many scripts can connect

Great tutorial, but bindableEvente are outdated because they can cause memory leaks if not used correctly.

1 Like

You’re using them wrong then. A event wrapper instance (aka bindableevent) cannot cause a memory leak on it’s own.

1 Like

It can, if you pass in any value that isn’t pure Lua, garbage collector wouldn’t be able to collect it.

At least provide valid stats if you want people to not use bindables all together. I’m not reading a long post that doesn’t mention memory leaks you mentioned.

It does.

RobloxSignal uses BindableEvents to make custom events.

Cool but you still don’t show any stats showing that it does indeed memory leak in that way.

I don’t understand how that is related to bindables memory leaking – it doesnt describe how they leak, nor does it provide stats that I’m literally begging for you to show.

I am new to this so I can be wrong unless you can correct my flaws.

Don’t say anything if you can’t provide anything to prove your point then. Do some research before posting.