Jump to content

How to Create Double-Arrays Like Array[1][2]?


manuelhimmler

Recommended Posts

Posted

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

Posted

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.

Posted
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

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

Posted

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!

  • 2 weeks later...
Posted

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

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

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

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