manuelhimmler Posted November 14, 2009 Share Posted November 14, 2009 Hi Community? I tried to create double arrays for more than a hour and i failed, I hope you can help me. I wanted to write this PAWN-Code in LUA: new Float:Hospitals[8][4] = { {1634.4591,1768.1781,10.8203,270.0}, {1225.4983,308.7397,19.7472,157.0}, {-2655.7307,636.2322,14.4531,188.0}, {1174.2993,-1323.4747,14.7891,270.0}, {2027.4967,-1406.1840,17.2150,191.0}, {-2119.7444,-2388.7043,30.6250,55.0}, {-316.1642,1054.7610,19.7422,354.0}, {-1514.6053,2523.7820,55.8071,0.0} }; Link to comment
Gamesnert Posted November 14, 2009 Share Posted November 14, 2009 Hospitals = { {1634.4591,1768.1781,10.8203,270.0}, {1225.4983,308.7397,19.7472,157.0}, {-2655.7307,636.2322,14.4531,188.0}, {1174.2993,-1323.4747,14.7891,270.0}, {2027.4967,-1406.1840,17.2150,191.0}, {-2119.7444,-2388.7043,30.6250,55.0}, {-316.1642,1054.7610,19.7422,354.0}, {-1514.6053,2523.7820,55.8071,0.0} }; This should do it I think. Link to comment
manuelhimmler Posted November 14, 2009 Author Share Posted November 14, 2009 I also thought so, but this isn't right! Link to comment
graetz Posted November 15, 2009 Share Posted November 15, 2009 function testaray() testarays ={ {1634.4591,1768.1781,10.8203,270.0}, {1225.4983,308.7397,19.7472,157.0}, {-2655.7307,636.2322,14.4531,188.0}, {1174.2993,-1323.4747,14.7891,270.0}, {2027.4967,-1406.1840,17.2150,191.0}, {-2119.7444,-2388.7043,30.6250,55.0}, {-316.1642,1054.7610,19.7422,354.0}, {-1514.6053,2523.7820,55.8071,0.0} }; outputDebugString("test aray: " ..testarays[1][1].."," ..testarays[1][2].."," ..testarays[1][3].."," ..testarays[1][4]) end addCommandHandler("arays", testaray) this maybe will help you Link to comment
50p Posted November 15, 2009 Share Posted November 15, 2009 function testaray() testarays ={ {1634.4591,1768.1781,10.8203,270.0}, {1225.4983,308.7397,19.7472,157.0}, {-2655.7307,636.2322,14.4531,188.0}, {1174.2993,-1323.4747,14.7891,270.0}, {2027.4967,-1406.1840,17.2150,191.0}, {-2119.7444,-2388.7043,30.6250,55.0}, {-316.1642,1054.7610,19.7422,354.0}, {-1514.6053,2523.7820,55.8071,0.0} }; outputDebugString("test aray: " ..testarays[1][1].."," ..testarays[1][2].."," ..testarays[1][3].."," ..testarays[1][4]) end addCommandHandler("arays", testaray) this maybe will help you DO NOT name variables the same as functions! Gamesnert example should work. I think you're doing something wrong if it doesn't work, manuelhimmler. Link to comment
manuelhimmler Posted November 15, 2009 Author Share Posted November 15, 2009 This works, but if I don't write the variabe definition in a function, there comes an error "attemt to index global "testaray" Edit: OK Sorry this error is only if I write the outputDebugstring in the game by runcode resource. Thanks at all! Link to comment
manuelhimmler Posted November 29, 2009 Author Share Posted November 29, 2009 Hi Community! I am here again with my problem! I wanted to write something in a variable: CarInfo[idx]["cModel"] = mysql_result(query,1,1) in the header of the script there is CarInfo={} and the error in the console is "attempt to index field '?' (a nil value) The problem is that I have to define every CarInfo like CarInfo[1]={}, CarInfo[2]={}, isn't there a better and easier solution Link to comment
norby89 Posted November 29, 2009 Share Posted November 29, 2009 The problem is that I have to define every CarInfo like CarInfo[1]={}, CarInfo[2]={}, isn't there a better and easier solution No, unless you know the car ids range in the beginning, then you could do it in a loop. Link to comment
manuelhimmler Posted November 29, 2009 Author Share Posted November 29, 2009 I know the CarInfo in the beginnig btw. I haven't to know it because i write as much data it in a loop as much data it is in the mysql database. Link to comment
norby89 Posted November 30, 2009 Share Posted November 30, 2009 I know the CarInfo in the beginnig btw. I haven't to know it because i write as much data it in a loop as much data it is in the mysql database. Then there's no problem, you just do: CarInfo[idx] = {} CarInfo[idx]["cModel"] = mysql_result(query,1,1) 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