Problem on assignment -
Sk1lleD - 22.12.2013
Hi there,
I was making a custom vehicle system, but on compiling I get this error and I don't undestand why
Код:
error 032: array index out of bounds (variable "Car")
Here's my code:
pawn Код:
enum vInfo
{
cOwner[30],
cModel,
cPrice,
cCol1 = 0,
cCol2 = 0
};
new Car[MAX_VEHICLES][vInfo];
pawn Код:
forward CreaVeh(playerid, model, price);
public CreaVeh(playerid, model, price)
{
if(GetPlayerMoney(playerid) >= price)
{
new Float:X, Float:Y, Float:Z;GetPlayerPos(playerid, X, Y, Z);
autom[playerid] = CreateVehicle(model, X, Y+2.0, Z, 0.0, 0, 0, 60);
PutPlayerInVehicle(playerid, autom[playerid], 0);
new id = autom[playerid];
format(Car[id][cOwner], 30, PlayerName(playerid));
new msg[256];
format(msg, sizeof(msg), "DEBUG: Owner: %s", Car[id][cOwner]);
SCM(playerid, -1, msg);
Car[id][cPrice] = price; //error
Car[id][cModel] = model; //error
Car[id][cCol1] = 0;
Car[id][cCol2] = 0;
TogglePlayerControllable(playerid, 0);
inColor[playerid] = 1;
}
return 1;
}
The problem comes when I assign to the varible Car[id][cPrice] a value
Someone can help?
Re: Problem on assignment -
Konstantinos - 22.12.2013
Do not use values in enum. Those you see are indexes of it and not initialized values.
pawn Код:
enum vInfo
{
cOwner[30],
cModel,
cPrice,
cCol1,
cCol2
};
Also use stock instead of forward/public.
Re: Problem on assignment -
Sk1lleD - 22.12.2013
Can't give you +REP, don't know why,
However, thanks, I've used the forward/public cause was making this vehicle system with dialogs, and wasn't working so I did some tries calling it by a timer or by command, and it worked, now using easyDialogs works also in dialogs...
Re: Problem on assignment -
Sk1lleD - 24.12.2013
Instead of making a new topic for the same system I'll post my trouble here...
I'm trying to set the plate with the SQLid of the vehicle, I got this 2 queries:
pawn Код:
//Called on the command to create the Vehicle
format(query, sizeof(query), "INSERT INTO car(Owner, Model, Price, Col1, Col2, cLock, cX, cY, cZ, cA, tID) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%f', '%f', '%f', '%f', '%d')",
RUS(playerid), //Name w/out '_'
model,
price,
Car[id][cCol1],
Car[id][cCol2],
Car[id][cLock],
Car[id][cX],
Car[id][cY],
Car[id][cZ],
Car[id][cA],
id);
print(query); // DEBUG
mysql_function_query(connection, query, false, "", "");
And it works, after that, I do:
pawn Код:
//Called when you press ENTER while chosing the colors of vehicle
new query[1024];
format(query, sizeof(query), "SELECT * FROM car WHERE tID = '%s' LIMIT 1", GetPlayerVehicleID(playerid));
mysql_function_query(connection, query, true, "SetPlate", "dd", playerid, GetPlayerVehicleID(playerid));
But it return 0 rows IG, while if I do the same code, copied by the print on console, on Phpmyadmin it will show the car...
What can I do?
Re: Problem on assignment -
Konstantinos - 24.12.2013
tID is an integer; therebefore, it's %d and not %s.
By the way, it's not recommended to store the vehicleid because a vehicle may or may not get the same vehicleid in the next restart.
Re: Problem on assignment -
Sk1lleD - 24.12.2013
It was '%d' originally, then this script won't work, so I copy - pasted this from another script that used PlayerName,
I had already fixed this, but it don't works...
I know, the 't' of tID stands for "tempID" I use it just to get the Unique SQLid from the DB
EDIT:
I've tried also with
SELECT * FROM car WHERE Owner = '%s' and formatting it with PlayerName, but it always found nothing... I've checked the DB, and there is the line, I've printed again this and copi-pasted it on SQL Execute, and it works...
I'm getting confused