Wisin Posted June 10, 2011 Share Posted June 10, 2011 Hi all, i have a problem with a table, if someone can help please. addEvent("returnCreatedCheckpoints",true) addEventHandler("returnCreatedCheckpoints",getRootElement(), function (checkpointsTable) checkpoints = {} I = 0 for i,v in pairs(checkpointsTable) do I = I +1 checkpoints[i] = {v[1], v[2], v[3]} end end) addEvent("createNewCheckpoint",true) addEventHandler("createNewCheckpoint",getRootElement(), function (player,id) local x, y, z = checkpoints[tonumber(id)][1], checkpoints[tonumber(id)][2], checkpoints[tonumber(id)][3] -- This outputs: attempt to index field '?' (a nil value) triggerClientEvent(player,"createCheckpointsForPlayer",player,x,y,z,id) end) So my problem is, when do triggerEvent("createNewCheckpoint",player,player,1) it outputs that error. Link to comment
Aibo Posted June 10, 2011 Share Posted June 10, 2011 what is the point of I = 0 and I = I +1? and where is the checkpointsTable created? and if your table has ordered indexes, you should use ipairs(), not pairs(). Link to comment
Wisin Posted June 10, 2011 Author Share Posted June 10, 2011 I = I +1 is to make a total checkpoint count. And the table is sent from the client side, i dont know if i must use ipairs or pairs. Link to comment
Aibo Posted June 10, 2011 Share Posted June 10, 2011 so how many you got in your total checkpoint count? Link to comment
Wisin Posted June 10, 2011 Author Share Posted June 10, 2011 (edited) that is fine, the checkpoints gets inserted in the table because i can do: addEvent("returnCreatedCheckpoints",true) addEventHandler("returnCreatedCheckpoints",getRootElement(), function (checkpointsTable) checkpoints = {} I = 0 for i,v in pairs(checkpointsTable) do I = I +1 checkpoints[i] = {v[1], v[2], v[3]} local x, y, z = checkpoints[i][1], checkpoints[i][2], checkpoints[i][3] outputDebugString(tostring(x)) outputDebugString(tostring(y)) outputDebugString(tostring(z)) end end) and will work fine Edited June 10, 2011 by Guest Link to comment
Aibo Posted June 10, 2011 Share Posted June 10, 2011 how can this work fine if "id" is (probably) nil? im sorry, but this is confusing. your event "returnCreatedCheckpoints" puts data from some table to another table. then, event "createNewCheckpoint" doesn't add any new data, but takes some from the table created by "returnCreatedCheckpoints". and where is "createNewCheckpoint" event is triggered? is "id" passed to it correctly? nvm, found that. Link to comment
Wisin Posted June 10, 2011 Author Share Posted June 10, 2011 Sorry, i forgot to change tonumber(id), and yes id is passed, i use triggerEvent to pass it. Link to comment
Aibo Posted June 10, 2011 Share Posted June 10, 2011 why dont you do something like: addEvent("createNewCheckpoint",true) addEventHandler("createNewCheckpoint",getRootElement(), function (player,id) outputDebugString(tostring(id)) -- and see what is there? local x, y, z = checkpoints[tonumber(id)][1], checkpoints[tonumber(id)][2], checkpoints[tonumber(id)][3] triggerClientEvent(player,"createCheckpointsForPlayer",player,x,y,z,id) end) Link to comment
Wisin Posted June 10, 2011 Author Share Posted June 10, 2011 because i already did that, and it says what it should say. Link to comment
Aibo Posted June 10, 2011 Share Posted June 10, 2011 problem is in this line then: checkpoints = {v[1], v[2], v[3]} this syntax doesn't put any values to checkpoints. probably because [ and ] used to denote a numeric index in a table, like {[1] = 1, [2] = "two"} you can try checkpoints = v, or copy this way local x,y,z = v[1], v[2], v[3] checkpoints[i] = { x, y, z } -- or checkpoints[i] = { unpack(v) } Link to comment
Wisin Posted June 10, 2011 Author Share Posted June 10, 2011 it doesnt work still same error as always... Link to comment
Wisin Posted June 12, 2011 Author Share Posted June 12, 2011 Does someone know how to fix this problem? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now