how to increase id number per create? -
drichie - 30.06.2013
as the title said the id doesnt increase it stay always in 0
here is my code
pawn Код:
CMD:cdoor(playerid,params[])
{
new string[200];
for(new idx=0; idx<MAX_DOOR; idx++)
{
//if(!DoorInfo[idx][dId])
//{
GetPlayerPos(playerid, DoorInfo[idx][dXe], DoorInfo[idx][dYe], DoorInfo[idx][dZe]);
DoorInfo[idx][dIe] = GetPlayerInterior(playerid);
DoorInfo[idx][dVe] = GetPlayerVirtualWorld(playerid);
GetPlayerFacingAngle(playerid, DoorInfo[idx][dAi]);
// Creating the door
CreateDynamicPickup(19198, 1, DoorInfo[idx][dXe], DoorInfo[idx][dYe], DoorInfo[idx][dZe]+0.3, DoorInfo[idx][dVe], DoorInfo[idx][dIe]);
format(string, sizeof(string), "ID: %d",idx);
CreateDynamic3DTextLabel(string,-1, DoorInfo[idx][dXe]-0.1, DoorInfo[idx][dYe], DoorInfo[idx][dZe]+0.5, 15);
idx = MAX_DOOR;
//}
}
return 1;
}
Re: how to increase id number per create? -
Macluawn - 30.06.2013
That is because you are setting it to 0 each time.
pawn Код:
idx = MAX_DOOR; //this line
Re: how to increase id number per create? -
WooTFTW - 30.06.2013
Just remove idx = MAX_DOOR
Re: how to increase id number per create? -
drichie - 30.06.2013
this is what happen
Re: how to increase id number per create? -
WooTFTW - 30.06.2013
Ah I see what you are trying to do there,
Код:
new idx; // Somewhere on top of your script
CMD:cdoor(playerid,params[])
{
new string[200];
GetPlayerPos(playerid, DoorInfo[idx][dXe], DoorInfo[idx][dYe], DoorInfo[idx][dZe]);
DoorInfo[idx][dIe] = GetPlayerInterior(playerid);
DoorInfo[idx][dVe] = GetPlayerVirtualWorld(playerid);
GetPlayerFacingAngle(playerid, DoorInfo[idx][dAi]);
// Creating the door
CreateDynamicPickup(19198, 1, DoorInfo[idx][dXe], DoorInfo[idx][dYe], DoorInfo[idx][dZe]+0.3, DoorInfo[idx][dVe], DoorInfo[idx][dIe]);
format(string, sizeof(string), "ID: %d",idx);
CreateDynamic3DTextLabel(string,-1, DoorInfo[idx][dXe]-0.1, DoorInfo[idx][dYe], DoorInfo[idx][dZe]+0.5, 15);
idx ++;
return 1;
}
You need to make the 'idx' variable global, basically what you were doing there that you made a loop, to create x amount of doors at the same position. I don't see why you needed the loop there
Re: how to increase id number per create? -
drichie - 30.06.2013
im making a dynamic door where will save using y_ini and that code is rip from Zgaming GM and im converting it to y_ini coz it uses dini then ive encountered this
this is my array in that code
pawn Код:
#define MAX_DOOR 100
enum dInfo
{
dId,
dVe,
dIe,
Float:dXe,
Float:dYe,
Float:dZe,
Float:dXi,
Float:dYi,
Float:dZi,
Float:dAi,
dIi,
dVi,
dExit
}
new DoorInfo[MAX_DOOR][dInfo];
Re: how to increase id number per create? -
Macluawn - 30.06.2013
Quote:
Originally Posted by WooTFTW
You need to make the 'idx' variable global
|
What a great way to mess things up. Other loops will affect the count if using idx variable as iterator (which he probably does)
Re: how to increase id number per create? -
WooTFTW - 30.06.2013
Quote:
Originally Posted by Macluawn
What a great way to mess things up. Other loops will affect the count if using idx variable as iterator (which he probably does)
|
Then just use any other word, is it so hard? Rename the idx, for example, createdDoors, or any other name which links to the variable's purpose
Re: how to increase id number per create? -
Universal - 30.06.2013
My suggestion would be create a function which returns the next unused ID. In this case you need to add a new boolean in your enum.
This is the function which would return the next unused ID. You will need no global arrays which store the ID anymore using this method. This method is also a better way for this situation, since you MIGHT make a mistake somewhere in your script with these
or
So basically heres the function:
pawn Код:
GetUnusedDoorID()
{
for (new i = 0; i < MAX_DOOR; i++) {
if (DoorInfo[i][dUsed]) continue;
return i;
}
return MAX_DOOR;
}
And make sure when you create a new door:
pawn Код:
DoorInfo[id][dUsed] = true;
And do the opposite when removing the door.
Hope this helps.
EDIT: Theres also one improvement for making it more "automatic". Instead of creating a new boolean in the enum and switching its value to true/false and checking it to return the next ID, you simply can check the doors position. If the X, Y, Z are equal to 0.0 then its probably not created which means the ID is unused. Heres an example:
pawn Код:
GetUnusedDoorID()
{
for (new i = 0; i < MAX_DOOR; i++) {
if (DoorInfo[i][dX] == 0.0 && DoorInfo[i][dY] == 0.0 && DoorInfo[i][dZ] == 0.0) {
return i;
}
}
return MAX_DOOR;
}
Re: how to increase id number per create? -
Macluawn - 30.06.2013
Quote:
Originally Posted by WooTFTW
Then just use any other word, is it so hard? Rename the idx, for example, createdDoors, or any other name which links to the variable's purpose
|
If he couldnt see such a simple mistake, do you really think he would think of renaming the variable?