Understanding foreach.
#1

So, i'm creating entrances system using foreach and djson.
It looks like that
pawn Код:
enum dInfo
{
    Float:dExteriorX,
    Float:dExteriorY,
    Float:dExteriorZ,
    dExteriorInt,
    Float:dInteriorX,
    Float:dInteriorY,
    Float:dInteriorZ,
    dInteriorInt,
    dName[128],
    dPp
}
new DoorInfo[MAX_DOORS][dInfo];
Everybody know what is this for Enum for entrances.
And then
pawn Код:
new Iterator:Doors<MAX_DOORS>, dCount;
public OnGameModeInit()
{
        for(new d=0;d< MAX_DOORS;d++)
    {
        LoadDoor(d);
    }
        return 1;
}


stock LoadDoor(id)
{
    new string[128], string2[128], name[128];
    format(string, sizeof(string), "Door_%d", id);
    if(djIsSet(DOORS_FILE, string))
    {
        format(string2, sizeof(string2),"Door_%d/ExteriorX", id); DoorInfo[id][dExteriorX] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/ExteriorY", id); DoorInfo[id][dExteriorY] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/ExteriorZ", id); DoorInfo[id][dExteriorZ] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/ExteriorInt", id); DoorInfo[id][dExteriorInt] = djInt(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/InteriorX", id); DoorInfo[id][dInteriorX] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/InteriorY", id); DoorInfo[id][dInteriorY] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/InteriorZ", id); DoorInfo[id][dInteriorZ] = djFloat(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/InteriorInt", id); DoorInfo[id][dInteriorInt] = djInt(DOORS_FILE, string);
        format(string2, sizeof(string2),"Door_%d/Name", id); format(name, sizeof(name), "%s", dj(DOORS_FILE, string2)); DoorInfo[id][dName] = name;
        Iter_Add(Doors, id);
        DoorInfo[id][dPp] = CreateDynamicPickup(1239, 2, DoorInfo[id][dExteriorX], DoorInfo[id][dExteriorY], DoorInfo[id][dExteriorZ], -1, DoorInfo[id][dExteriorInt], -1, 50.0);
        return 1;
    }
    return 1;
}
stock AddDoor(Float:x, Float:y, Float:z, interior, name[])
{
    new string2[128];
    dCount ++;
    Itter_Add(Doors, dCount);
    format(string2, sizeof(string2), "Door_%d/ExteriorX", dCount); djSetFloat(DOORS_FILE, string2, x);
    format(string2, sizeof(string2), "Door_%d/ExteriorY", dCount); djSetFloat(DOORS_FILE, string2, y);
    format(string2, sizeof(string2), "Door_%d/ExteriorZ", dCount); djSetFloat(DOORS_FILE, string2, z);
    format(string2, sizeof(string2), "Door_%d/ExteriorInt", dCount); djSetInt(DOORS_FILE, string2, interior);
    format(string2, sizeof(string2), "Door_%d/InteriorX", dCount); djSetFloat(DOORS_FILE, string2, 0);
    format(string2, sizeof(string2), "Door_%d/InteriorY", dCount); djSetFloat(DOORS_FILE, string2, 0);
    format(string2, sizeof(string2), "Door_%d/InteriorZ", dCount); djSetFloat(DOORS_FILE, string2, 0);
    format(string2, sizeof(string2), "Door_%d/InteriorInt", dCount); djSetInt(DOORS_FILE, string2, 0);
    format(string2, sizeof(string2), "Door_%d/Name", dCount); djSet(DOORS_FILE, string2, name);
    LoadDoor(dCount);
    return 1;
}
The problem is when i use AddDoor function, it overrides Door_1 informations instead of creating new line in .ini file. and it fails to load informations from file, because pickup isn't created where it should be, but on 0, 0, 0 coords.
Reply


Messages In This Thread
Understanding foreach. - by sekol - 24.03.2011, 16:54
Re: Understanding foreach. - by armyoftwo - 24.03.2011, 17:06
Re: Understanding foreach. - by sekol - 24.03.2011, 17:45
Re: Understanding foreach. - by armyoftwo - 25.03.2011, 07:10
Re: Understanding foreach. - by sekol - 25.03.2011, 07:17
Re: Understanding foreach. - by armyoftwo - 25.03.2011, 07:21
Re: Understanding foreach. - by sekol - 25.03.2011, 07:23
Re: Understanding foreach. - by sekol - 25.03.2011, 13:17

Forum Jump:


Users browsing this thread: 1 Guest(s)