PDA

View Full Version : Loading


Micko123
04/12/2016, 08:16 AM
forward AtmsLoad();
public AtmsLoad()
{
new rows = cache_num_rows();
if(rows)
{
new index = Iter_Free(i_ATM);
for(new i = 0; i < rows; i++)
{
cache_get_value_int(i, "ID", AtmInfo[index][aID]);
cache_get_value_float(i, "PosX", AtmInfo[index][aPosX]);
cache_get_value_float(i, "PosY", AtmInfo[index][aPosY]);
cache_get_value_float(i, "PosZ", AtmInfo[index][aPosZ]);
cache_get_value_float(i, "Angle", AtmInfo[index][aAngle]);
cache_get_value_int(i, "VW", AtmInfo[index][aVW]);
cache_get_value_int(i, "Interior", AtmInfo[index][aInt]);
AtmInfo[i][AtmExist] = true;
Iter_Add(i_ATM, index);
CreateAtm(index);
}
printf("ATMs loaded: %d", rows);
}
return 1;
}

ID's are saved as 1, 2, 3, 4,.. in DB and that is fine..
But every ID is loading as 0.. Any ideas?

EDIT: When I am creating ATMs ther are created with ID 1, 2, 3, 4.. so loading is problem only..

Vince
04/12/2016, 08:23 AM
Shouldn't the Iter_Free line be inside the loop? As I see it you're now constantly overwriting the same index.

Micko123
04/12/2016, 08:24 AM
So you are suggesting this??

forward AtmsLoad();
public AtmsLoad()
{
new rows = cache_num_rows();
if(rows)
{
for(new i = 0; i < rows; i++)
{
new index = Iter_Free(i_ATM);
cache_get_value_int(i, "ID", AtmInfo[index][aID]);
cache_get_value_float(i, "PosX", AtmInfo[index][aPosX]);
cache_get_value_float(i, "PosY", AtmInfo[index][aPosY]);
cache_get_value_float(i, "PosZ", AtmInfo[index][aPosZ]);
cache_get_value_float(i, "Angle", AtmInfo[index][aAngle]);
cache_get_value_int(i, "VW", AtmInfo[index][aVW]);
cache_get_value_int(i, "Interior", AtmInfo[index][aInt]);
AtmInfo[i][AtmExist] = true;
Iter_Add(i_ATM, index);
CreateAtm(index);
}
printf("ATMs loaded: %d", rows);
}
return 1;
}
If yes there is a problem. It is loading ID's as 0, 1..
Problem is that ID 0 is treated as ID 1
ID 1 is treated as ID 2
ID 2 is treated as ID 3...

Micko123
04/12/2016, 08:36 AM
-FIXED-
This is loading

forward AtmsLoad();
public AtmsLoad()
{
new rows = cache_num_rows();
if(rows)
{
new index = Iter_Free(i_ATM);
for(new i = 0; i < rows; i++)
{
cache_get_value_int(i, "ID", AtmInfo[index][aID]);
cache_get_value_float(i, "PosX", AtmInfo[index][aPosX]);
cache_get_value_float(i, "PosY", AtmInfo[index][aPosY]);
cache_get_value_float(i, "PosZ", AtmInfo[index][aPosZ]);
cache_get_value_float(i, "Angle", AtmInfo[index][aAngle]);
cache_get_value_int(i, "VW", AtmInfo[index][aVW]);
cache_get_value_int(i, "Interior", AtmInfo[index][aInt]);
AtmInfo[i][AtmExist] = true;
Iter_Add(i_ATM, index);
CreateAtm(index);
}
printf("ATMs loaded: %d", rows);
}
return 1;
}

Problem was here

CreateAtm(id)
{
new string[120];
format(string, sizeof(string), ""SERVERBLUE"ID: "WHITE"%d\n"SERVERBLUE"ATM\n"WHITE"To use ATM press 'Y'", AtmInfo[id][aID]);
AtmLabel[id] = CreateDynamic3DTextLabel(string, 0x1D9F00AA, AtmInfo[id][aPosX], AtmInfo[id][aPosY], AtmInfo[id][aPosZ]+0.1, 25.0, _, _, _, 0, 0, _, _);
AtmObject[id] = CreateDynamicObject(ATM_OBJECT, AtmInfo[id][aPosX], AtmInfo[id][aPosY], AtmInfo[id][aPosZ], 0.0, 0.0, AtmInfo[id][aAngle], AtmInfo[id][aVW], AtmInfo[id][aInt], _, _);
return 1;
}


Instead of AtmInfo[id][aID] I was creating ID with just wiriting ID there xD

Stinged
04/12/2016, 09:19 AM
Your loading is most likely bugged.
I'm pretty sure Vince is right about Iter_Free.

You're re-using the same index (Iter_Free returns the nearest 'free' index inside of the iterator)
If you use it just once, you'll always be using the same index, so you'll be overwriting the old data.

Micko123
04/12/2016, 09:34 AM
So you are suggesting this??

code

If yes there is a problem. It is loading ID's as 0, 1..
Problem is that ID 0 is treated as ID 1
ID 1 is treated as ID 2
ID 2 is treated as ID 3...

Look at that.. I did it my way and it is working like charm xD