Jump to content

After sending table over triggerEvent, handler function cannot call table's method functions


John Smith

Recommended Posts

Hello.

I am using this piece of code as a test example here:

Mother = {};
Mother.__index = Mother;

addEvent("onClientHandlerEvent");

function Mother:new()

	local self = setmetatable( {}, Mother );

	self.type = "Mother";

	triggerEvent("onClientHandlerEvent", localPlayer, self);

	return self;

end


function handlerTable(theTable)
	outputDebugString(tostring(theTable:getProperty("type"))); -- attempt to call method :getProperty (a nil value)
end
addEventHandler("onClientHandlerEvent", root, handlerTable);

function Mother:getProperty(property)
	return self[property];
end



local myMother = Mother:new();
outputChatBox(tostring(myMother:getProperty("type"))); -- works

 

The issues that I'm having with this is that when I transfer the table with triggerEvent, function which handles that custom event cannot call any custom methods because apparently they're 'nil'.

Why is this happening? Is this a triggerEvent issue?

Link to comment
24 minutes ago, Gravestone said:

I hope this works for you.


function handlerTable(theTable)
	local theTable = Mother:new();
	outputDebugString(tostring(theTable:getProperty("type"))); -- attempt to call method :getProperty (a nil value)
end
addEventHandler("onClientHandlerEvent", root, handlerTable);

 

You're using theTable as a function argument and then creating it below which is a leftover by the way, and the handler function is supposed to handle the table (aka recieve it), not create it.

However thank you for trying to help me out, but this isn't what I'm looking for

Edit:

Well, this seems to be more an issue with triggerEvent, so you guys don't need to reply anything.

Edited by John Smith
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...