passing table and value to add to table as raiseEvent arguments

Post Reply
redbananasea
Posts: 1
Joined: Tue Aug 03, 2021 5:49 pm

passing table and value to add to table as raiseEvent arguments

Post by redbananasea »

In one script, I declare a bunch of tables, among them, table_a, with:

Code: Select all

table_a = {}
Another script, table_adder, is set up with the function:

Code: Select all

function table_adder (table, value)
table.insert(table, value)
end
The script has "table_adder" registered as an event handler. The purpose of the script is to accept the name of any of my previously declared tables and a numeric value and add the value to the table.

When I raise the table_adder event and call the function with:

Code: Select all

raiseEvent("table_adder", table_a, 1)
I get an error: bad argument #1 to 'insert' (table expected, got string). When I check the value of table within the function, I can see that its value is table_adder, the name of the function, not table_a, the table I was trying to pass. What am I doing wrong?

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: passing table and value to add to table as raiseEvent arguments

Post by demonnic »

The first parameter passed in for any event is the name of the event, so you'd want to change the function signature to table_adder(event, table, value) and it should work.

Post Reply