lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hello guys,

I am using a script which updates the action of a character in game. Each tme the script is called with the pointer to a character, which I use as a key to a global table to access the arguments and other variables of the action.

The problem arrives when one character i executing one script when I try to pass parameters to another. The characters that was  already executing  stops, because the argument stored in its table turns to NULL, but it is a lightuserdata! This should not be freed by C?

I pass the parameters to one script and after that I set the parameters to NULL, to be sure that the other characters do not get it.

Here is my code;

key= string.sub(tostring(id), string.find(tostring(id),pointer))

if table_arg[key] == nil then

function endCurrentAction()

--set the name of the action based on debug information
local da= debug.getinfo(1,"S")
action= "">

--if this is the first time this action is called
--or if this is the first action to be called for this character
--set the action in the table to this action
if table_arg[key]["action"] ~= action then
        table_arg[key]["action"]= action
--------------------Initialization Begin---------------
--------------------Initialization End-----------------

-- everytime new arguments are passed to the script
-- even when the same action remains, the arguments in
-- the character's table must be changed
if arg0 ~= nil then
--------------Insert all Args to the Table-------------
        table_arg[key]["arg0"]= arg0
        print("new_arg" .. tostring(arg0))



--local target_position= table_arg[id].arg0
local target_position= table_arg[key]["arg0"]
--print("key " .. key)
--print("target  " .. tostring(target_position))
if target_position == nil then
        print("new_arg" .. tostring(arg0))
        --WHY IT ENTERS HERE???

local current_position = id:getPosition()

id:changeDirection(target_position.x, target_position.z, dt)


local dist= math.sqrt( (target_position.x - current_position.x)*(target_position.x - current_position.x) +
                       (target_position.y - current_position.y)*(target_position.y - current_position.y) +
                       (target_position.z - current_position.z)*(target_position.z - current_position.z)

local character_data= id:getCharacterData()

--check if he arrived at the destination
if dist <= character_data.size then