the tables are same as the variables but they are all the same table. & temporary. I don't need the data to be saved, hence the use of the temporary local table, each time the function is called, it updates the data inside of the tables.
sure I could have created empty local variables outside of the function but I wouldn't use them on the inside of a function as it creates a new table entry each time you call local inside of a function & not much point in that!
I know Lua is pretty efficient now & I enjoy using whenever I can instead of using the pre-made editor action parts as it is just far quicker to type a few lines of code than it is to click here & there.
Here's my version of the script you wrote above...
prevItem = nil -- initial value of previously highlighted item
function checkItemStatus()
if prevItem ~= nil then prevItem:setValue(VAnimationFirstFrame, 1); prevItem:setValue(VAnimationLastFrame, 1); prevItem = nil end
-- + --
if game:getLink(VGameCurrentObject):getId().tableId == eObjects then
if game:getLink(VGameCurrentObject):getBool(VObjectIsItem) then
prevItem = getObject("ActiveAnimations[" .. game:getLink(VGameCurrentObject):getName() .."]"); prevItem:setValue(VAnimationFirstFrame, 2); prevItem:setValue(VAnimationLastFrame, 2)
end
end
end
function onMouseEvent(eventType)
if eventType == eEvtMouseMove then checkItemStatus() end
end
registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove})
my version uses the mouseEvent handler instead & is a little more compact.
I'm not sure if you told him or not but he needs to add a line of code to the first frame of each item's animation to force it to only play the first frame.
getObject("ActiveAnimations[item_name]"):setValue(VAnimationLastFrame, 1)