Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Creating a event/listener?

Asked by
RM0d 305 Moderation Voter
9 years ago

I'm writing a peice of code for my backpack.

x = AddSlot(script.Parent.Container.Slot1)

x.ItemAdded:connect(function(itemAdded) print(itemAdded) end)
x.ItemRemoved:connect(function(ItemRemoved)  print(ItemRemoved) end)

If you look at line 3&4 how Would I make it be able to do that.

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Very simply, by utilizing the ROBLOX-provided LuaSignals.

I'm assuming here that your AddSlot function returns a Table:

local CreateSignal = LoadLibrary('RbxUtility').CreateSignal

function AddSlot(slot)
    local newSlot = {}

    --code

    newSlot.ItemAdded = CreateSignal()
    newSlot.ItemRemoved = CreateSignal()
end

Now, on its own, this does nothing, and I can't write the code to make it do something without seeing the rest of the AddSlot function.

What you need to do is call the fire method on those two LuaSignals, passing in the item that was added/removed, wherever you handle adding/removing items from Slots.

0
Thank you so much, for your help. RM0d 305 — 9y
Ad

Answer this question