Snoozy Posted May 26, 2011 Share Posted May 26, 2011 Hey now I'm currently working on my business system which is built together with a interior system I got, now I got this problem since the loading of the business and the interior is in two seperate files, I'm saving the interiors like in a variable similar to this: IntInfo = {} -- Later in code IntInfo[idx] = {} But then when I try and use IntInfo in my business loading lua it doesn't seem to work, it errors me like that the output from the IntInfo in that file just equals a ? Is there some other way you should do this or what is going on? If you need to see more code or anything then just ask me Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 didnt really get what you mean, show full error message Link to comment
qaisjp Posted May 26, 2011 Share Posted May 26, 2011 He wants to transfer a variable from one resource to another. Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 oh, imo setElementData(getRootElement(),"dataname",data) getElementData(getRootElement(),"dataname") is a brilliant way. Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 Oh well it seems like the variables wasn't even the problem lol, but yea karlis the problem with that is that I would have to like call all the datanames like int(IDhere)_nameofthething ? Else it wouldn't work cause I got a lot of interiors not just one? Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 just send the table as data then Link to comment
qaisjp Posted May 26, 2011 Share Posted May 26, 2011 I forgot about element data. I was gonna say exports. Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 What you mean by sending the table as data? Care to explain a bit cause I don't really get it. Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 intInfo={} intInfo[1]={} ... --and so on setElementData(getRootElement(),"dataname",intInfo) Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 Would that single setElementData transfer all the other IntInfo[1]={} also? Or would I have to make one for each, also would it then transfer everything inside like IntInfo[1].X and IntInfo[1].Y in that one elementdata? Link to comment
qaisjp Posted May 26, 2011 Share Posted May 26, 2011 if you do intInfo, it also sends all it's'children' so, it would transfer everything (IntInfo[1] .. IntInfo[2].Y and soo on..) Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 yes, it would be advisable to don't have it too big(multidimensional arrays with 1000+keys per dimension can cause trouble.) Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 how would I then use getElementData to get it all out and work as intinfo and all that Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 how would I then use getElementData to get it all out and work as intinfo and all that intInfo=getElementData(getRootElement(),"data name") --now you can access everything that is stored inside that table, even other tables. Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 I'm having this one error that I can't seem to fix, when I get to the business and press R it gives me the error: [2011-05-26 17:51:10] ERROR: boulevard\business\server.lua:56: attempt to index field '?' (a nil value) The line is: setElementPosition (source,IntInfo[bizInfo[idx].Interior].X,IntInfo[bizInfo[idx].Interior].Y,IntInfo[bizInfo[idx].Interior].Z,true) Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 you need to sync both BizInfo and intInfo then. Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 What you mean by syncing them since the BizInfo is created in that lua anyways and shouldn't be any problems with it since it's used another place in the script where it is loaded without having to set that ones elementdata if that's what you mean? Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 well, you used so much tables inside a tables leading a key to another table inside a table with a key to another double table that i got confused... anyway, that error means some of the tables inside tables are not created Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 Well yeah it gets confusing when your dealing with tons of tables inside another tons of tables but I'm pretty sure that it's not the BizInfo cause it's used like 2 lines up where its used to check distance between player and the location of the business and it outputs that it's found and so on. With the IntInfo I did following: (maybe I've done something wrong) IntInfo = {} function loadInt() local interior = mysql_connect("******", "******", "*****, "******") if (interior) then local maxi = mysql_query(interior,"SELECT * FROM interior") if (maxi) then maxin = mysql_num_rows(maxi) if (maxin) then for idx=0, maxin do query = "SELECT * FROM interior WHERE InteriorID = '"..idx.."'" result = mysql_query(interior,query) IntInfo[idx] = {} if (result) then row = mysql_fetch_row(result) if (row) then IntInfo[idx].ID = row[1] IntInfo[idx].X = row[2] IntInfo[idx].Y = row[3] IntInfo[idx].Z = row[4] IntInfo[idx].Interior = row[5] IntInfo[idx].Name = row[6] outputServerLog("Loaded Interior -"..row[6].."-") end end mysql_free_result(result) end end end end mysql_close(interior) setElementData(getRootElement(),"IntInfo",IntInfo) end setTimer(loadInt,500, 1) at end I do the setelementdata thing as shown above. Now in the business code: IntInfo = getElementData(getRootElement(),"IntInfo") function Enter(source,key,keystate) if keystate == "down" then if getElementData(source,"BizEntered") == 0 then for idx=1, maxBiz do x,y,z = getElementPosition(source) if getDistanceBetweenPoints3D(x, y, z, BizInfo[idx].SpawnX, BizInfo[idx].SpawnY, BizInfo[idx].SpawnZ) <= 1 then outputChatBox("24/7",source) setElementPosition(source,IntInfo[BizInfo[idx].Interior].X,IntInfo[BizInfo[idx].Interior].Y,IntInfo[BizInfo[idx].Interior].Z,true) setElementInterior(source,IntInfo[BizInfo[idx].Interior].Interior) setElementData(source,"BizEntered",idx) else outputChatBox("Not in range of any biz",source) end end else if getDistanceBetweenPoints3D(x,y,z,IntInfo[BizInfo[getElementData(source,"BizEntered")].Interior].X,IntInfo[BizInfo[getElementData(source,"BizEntered")].Interior].Y,IntInfo[BizInfo[getElementData(source,"BizEntered")].Interior].Z) <= 3 then setElementPosition(source,BizInfo[getElementData(source,"BizEntered")].SpawnX,BizInfo[getElementData(source,"BizEntered")].SpawnY,BizInfo[getElementData(source,"BizEntered")].SpawnZ,true) setElementData(source,"BizEntered",0) setElementInterior(source,0) end end end end Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 don't think you can use mysql node as an key, and btw fix first code, one quote is missing Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 What you mean by not being able to use a mysql node as an key? I'm just saving information from mysql onto a table? Sorry but i'm not really getting it Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 nvm, interior and Interior isn't the same, anyway, i don't see where is Interior defined? Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 Mhm does two tables doens't work together, like when you cross the information? I just did some debugging and found this problem: outputChatBox(IntInfo[1].X,source) -- WORKING outputChatBox(IntInfo[idx].X,source) -- WORKING outputChatBox(IntInfo[BizInfo[idx].Interior].X,source) -- NOT WORKING outputChatBox(IntInfo[int].X,source) -- NOT WORKING which shows that the ones where you like use the information from BizInfo into IntInfo does not work and that's what makes the error? Link to comment
karlis Posted May 26, 2011 Share Posted May 26, 2011 try splitting it into few variables, and adding up the tree step by step Link to comment
Snoozy Posted May 26, 2011 Author Share Posted May 26, 2011 what you mean? Could you like try and explain it a bit more in details? Cause splitting both in variables then you can't like combine them afterwards? 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