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
10 years ago

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

1x = AddSlot(script.Parent.Container.Slot1)
2 
3x.ItemAdded:connect(function(itemAdded) print(itemAdded) end)
4x.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
10 years ago

Very simply, by utilizing the ROBLOX-provided LuaSignals.

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

01local CreateSignal = LoadLibrary('RbxUtility').CreateSignal
02 
03function AddSlot(slot)
04    local newSlot = {}
05 
06    --code
07 
08    newSlot.ItemAdded = CreateSignal()
09    newSlot.ItemRemoved = CreateSignal()
10end

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 — 10y
Ad

Answer this question