Jump to content

Variable question


Snoozy

Recommended Posts

Posted

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 :)

Posted

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?

Posted

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?

  • MTA Team
Posted

if you do intInfo, it also sends all it's'children' so, it would transfer everything (IntInfo[1] .. IntInfo[2].Y and soo on..)

Posted
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. 
  

Posted

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) 

Posted

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?

Posted

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

Posted

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 

Posted

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

Posted

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?

Posted

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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...