PDA

View Full Version : takeObject's callback cannot send params to another object or to Global.



MrStump
01-31-2017, 01:28 AM
ISSUE:
Callbacks from takeObject will not correctly pass their parameters.params field to other objects or to Global. It will only work on self. This bug is simple to reproduce, and I've included the code I was using along with instructions below for how I was setting it up/using it.

EXAMPLE CODE:

--Apply this script to an object.
--anotherObject is a different object, deck is a deck of cards.
function onload()
local anotherObject = getObjectFromGUID('40b304')
local deck = getObjectFromGUID("03401d")
deck.takeObject({
position = {0, 1.05, 0}, callback = "dealCards",
callback_owner = self, params = {someWord = "test"}
})
end

function dealCards(cardTaken, params)
cardTaken.flip()
print(params.someWord)
end

HOW TO REPRODUCE:
Spawn a deck and 2 objects. Apply this full script to object 1. Add the deck's GUID to local deck = getObjectFromGUID("03401d") and the second object to local anotherObject = getObjectFromGUID('40b304'). Save and apply, and it should run just fine, print "test" to game chat and flip the card over after it is placed.

Now, move function dealCards to object 2. Change the takeObject parameter to have callback_owner = anotherObject. Save and apply. The card will be drawn, but you will get an error, there will be no flip and no "test" print.

The same is true if you move the code to global and use callback_owner = Global.