Jump to content

Variable question


Snoozy

Recommended Posts

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

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

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

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

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

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

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

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