lua-users home
lua-l archive

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


Sorry, It is not a lightuserdata.

In fact it is passed by tolua_pushusertype()... , but that does not solve anything.

Everything works right when only one character is executing the script, but not with 2 characters doing different things. I do not see any conflict whatsoever that could lead to this. There are two tables storing arguments and I am sure that both tables are distinct.

2009/11/8 zweifel <zweifel@gmail.com>
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;


pointer="x%x+"
key= string.sub(tostring(id), string.find(tostring(id),pointer))

if table_arg[key] == nil then
        table_arg[key]={}
        --id={}
        print(key)
end

function endCurrentAction()
        table_arg[key]["action"]=nil
        id:System_endCurrentAction()
end

--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---------------
        id:beginAnimation(WALK_ANIM)
--------------------Initialization End-----------------
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))
--------------------------------------------------------
end



----------------------Main------------------------------

--print(id)


--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
        endCurrentAction()
        print("new_arg" .. tostring(arg0))
        --WHY IT ENTERS HERE???
end

local current_position = id:getPosition()


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

--print(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
        endCurrentAction();
end