Array index out of bounds
#1

Im trying to make a dialog to select certain coords from a list I made


Код:
new Float:InteriorCoords[25][3] = 
{
	{244.41,305.032,999.148}//Small Cottage 1 
	{2218.35,-1076.26,1050.48}//Light Living 1 
etc etc etc


Код:
case 0:
			{
				SetPVarFloat(playerid,"HouseExitX", InteriorCoords[0][1]);
				SetPVarFloat(playerid,"HouseExitY", InteriorCoords[0][2]);
				SetPVarFloat(playerid,"HouseExitZ", InteriorCoords[0][3]);
				SetPVarInt(playerid, "HouseInterior", 1);
			}
			case 1:
			{
				SetPVarFloat(playerid,"HouseExitX", InteriorCoords[1][1]);
				SetPVarFloat(playerid,"HouseExitY", InteriorCoords[1][2]);
				SetPVarFloat(playerid,"HouseExitZ", InteriorCoords[1][3]);
				SetPVarInt(playerid, "HouseInterior", 1);
			}
etc etc etc
But I get the error: Array index out of bounds
Reply
#2

At second "definition" ( [3] ). You have houseexitx, y, z. Try to define it [4] instead of [3]

new Float:InteriorCoords[25][4] .
Reply
#3

Quote:
Originally Posted by abyss.
Посмотреть сообщение
At second "definition" ( [3] ). You have houseexitx, y, z. Try to define it [4] instead of [3]

new Float:InteriorCoords[25][4] .
Yes that fixed it, Maybe you can help me with the next thing, My line is to long of the ShowPlayerDialog

Код:
ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Houses", "Small Cottage\nLight Living\nDirty Laundry\nFancy Apartment\nHouse Ghetto Small\nGhetto Project Apartment Small\nLS Trailer\nLong John\nApartment Near Beach Medium\nHuge House at Vinewood\nMedium House at SF\nSmall Project LV\nHallway House\nLight Apartment\nSmall Nice House in SF\nUgly but big\nShithole\nMinor Manor\nPink house in SF\n3 Story Condo in SF\n4 Story Condo in SF\nMajor Manor\nMexican Style House\nSimple House\nMadd Doggs House", "Accept", "Cancel");
Any way of having such a list and still have it be accepted?
Reply
#4

Just leave these brackets empty if you use a predefined array
if you still get an error than you did something wrong afterwards
pawn Код:
new Float:InteriorCoords[][] =  {};
The problem is that you start with 1 in the second dimension, it should be
pawn Код:
SetPVarFloat(playerid,"HouseExitX", InteriorCoords[0][0]);
SetPVarFloat(playerid,"HouseExitY", InteriorCoords[0][1]);
SetPVarFloat(playerid,"HouseExitZ", InteriorCoords[0][2]);
If your line is to long you could place it on an extra line
pawn Код:
ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Houses",
    "Small Cottage\nLight Living\nDirty Laundry\nFancy Apartment\nHouse Ghetto Small\nGhetto Project Apartment Small\nLS Trailer\nLong John\nApartment Near Beach Medium\nHuge House at Vinewood\nMedium House at SF\nSmall Project LV\nHallway House\nLight Apartment\nSmall Nice House in SF\nUgly but big\nShithole\nMinor Manor\nPink house in SF\n3 Story Condo in SF\n4 Story Condo in SF\nMajor Manor\nMexican Style House\nSimple House\nMadd Doggs House",
    "Accept", "Cancel"
);
The line limit is around ~500 char, this will only raise it by a little

For really longs strings you should define them globally

pawn Код:
// strings must be placed right after each other
new
    DialogText1[] = "Small Cottage\nLight Living\nDirty Laundry\nFancy Apartment\nHouse Ghetto Small\nGhetto Project Apartment Small\nLS Trailer\nLong John\nApartment Near Beach Medium\nHuge House at Vinewood\nMedium House at SF\nSmall Project LV",
    DialogText2[] = "Hallway House\nLight Apartment\nSmall Nice House in SF\nUgly but big\nShithole\nMinor Manor\nPink house in SF\n3 Story Condo in SF\n4 Story Condo in SF\nMajor Manor\nMexican Style House\nSimple House\nMadd Doggs House"
);
// OnGameModeInit
    // You could also write a simple function to conect these strings
    DialogText2[sizeof DialogText2 - 1] = EOS; // this is necessary otherwise the compiler will ignore it as it is never used
    DialogText1[sizeof DialogText1 - 1] = '\n'; // concact both strings with '\n' (we left that one away at the end of the first string)
// Your dialog
    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Houses", DialogText1, "Accept", "Cancel");
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just leave these brackets empty if you use a predefined array
if you still get an error than you did something wrong afterwards
pawn Код:
new Float:InteriorCoords[][] =  {};
The problem is that you start with 1 in the second dimension, it should be
pawn Код:
SetPVarFloat(playerid,"HouseExitX", InteriorCoords[0][0]);
SetPVarFloat(playerid,"HouseExitY", InteriorCoords[0][1]);
SetPVarFloat(playerid,"HouseExitZ", InteriorCoords[0][2]);
If your line is to long you could place it on an extra line
pawn Код:
ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Houses",
    "Small Cottage\nLight Living\nDirty Laundry\nFancy Apartment\nHouse Ghetto Small\nGhetto Project Apartment Small\nLS Trailer\nLong John\nApartment Near Beach Medium\nHuge House at Vinewood\nMedium House at SF\nSmall Project LV\nHallway House\nLight Apartment\nSmall Nice House in SF\nUgly but big\nShithole\nMinor Manor\nPink house in SF\n3 Story Condo in SF\n4 Story Condo in SF\nMajor Manor\nMexican Style House\nSimple House\nMadd Doggs House",
    "Accept", "Cancel"
);
The line limit is around ~500 char, this will only raise it by a little

For really longs strings you should define them globally

pawn Код:
// strings must be placed right after each other
new
    DialogText1[] = "Small Cottage\nLight Living\nDirty Laundry\nFancy Apartment\nHouse Ghetto Small\nGhetto Project Apartment Small\nLS Trailer\nLong John\nApartment Near Beach Medium\nHuge House at Vinewood\nMedium House at SF\nSmall Project LV",
    DialogText2[] = "Hallway House\nLight Apartment\nSmall Nice House in SF\nUgly but big\nShithole\nMinor Manor\nPink house in SF\n3 Story Condo in SF\n4 Story Condo in SF\nMajor Manor\nMexican Style House\nSimple House\nMadd Doggs House"
);
// OnGameModeInit
    // You could also write a simple function to conect these strings
    DialogText2[sizeof DialogText2 - 1] = EOS; // this is necessary otherwise the compiler will ignore it as it is never used
    DialogText1[sizeof DialogText1 - 1] = '\n'; // concact both strings with '\n' (we left that one away at the end of the first string)
// Your dialog
    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Houses", DialogText1, "Accept", "Cancel");
Already fixed everything it is now fully working, Used strcat's for dialogs and changed the dimensions Thank you all for the help.

Edit*

Just one question why did I had to set

Код:
new Float:InteriorCoords[25][4] =  {};
If I only use 0,1,2 why would I need 4?
Reply
#6

You don't need 4, use 3 as you need only 3 numbers (0, 1, 2)
Reply
#7

Quote:
Originally Posted by ball
Посмотреть сообщение
You don't need 4, use 3 as you need only 3 numbers (0, 1, 2)
Any way of having the entire line put in without using multiple InteriorCoords[12][0],InteriorCoords[12][1],InteriorCoords[12][2].
Like maybe InteriorCoords[12] to just put the entire line in with its ,'s?
Reply
#8

It's difference. InteriorCoords[12][0] is normal value which you can use, but InteriorCoords[12] is an array of values. You can't use arrays in SetPVarFloat - generally you can nowhere use arrays in default functions, you can create these, for example

Код:
public OnGameModeInit()
{
	new Float:fArray[][] = {
	{0.0, 1.1, 2.2},
	{0.0, 1.1, 2.2},
	{0.0, 1.1, 2.2}};
	saveFloat(2, fArray[2]);
}
stock saveFloat(playerid, Float:theArray[]) printf("%.1f %.1f %.1f %d", theArray[0], theArray[1], theArray[2], playerid);
Reply
#9

Quote:
Originally Posted by ball
Посмотреть сообщение
It's difference. InteriorCoords[12][0] is normal value which you can use, but InteriorCoords[12] is an array of values. You can't use arrays in SetPVarFloat - generally you can nowhere use arrays in default functions, you can create these, for example

Код:
public OnGameModeInit()
{
	new Float:fArray[][] = {
	{0.0, 1.1, 2.2},
	{0.0, 1.1, 2.2},
	{0.0, 1.1, 2.2}};
	saveFloat(2, fArray[2]);
}
stock saveFloat(playerid, Float:theArray[]) printf("%.1f %.1f %.1f %d", theArray[0], theArray[1], theArray[2], playerid);
Yeah not for pvars but like for SetPlayerPos(playerid,InteriorCoords[12]); Would work?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)