Wut?? -
Micko123 - 27.08.2016
I donwloaded gamemode from internet. and i want to edit it. It is small gamemode in BaySide and i found something strange(at least for me). Dialogs are defined like this
PHP код:
enum
{
DIALOG_OTHER,
DIALOG_LOGIN,
DIALOG_REGISTER,
DIALOG_REGISTER_POL,
DIALOG_REGISTER_GODINE,
DIALOG_REGISTER_POTVRDA,
DIALOG_POSTAVKE,
DIALOG_POSTAVKE_IME,
DIALOG_POSTAVKE_SLOZINKA,
DIALOG_POSTAVKE_RCON,
DIALOG_POSTAVKE_SKINM,
DIALOG_POSTAVKE_SKINZ,
DIALOG_POSTAVKE_POS,
DIALOG_POSTAVKE_PNOVAC,
DIALOG_POSTAVKE_PLEVEL,
DIALOG_POSTAVKE_DEBUG,
DIALOG_CREATE,
DIALOG_CREATE_RENT,
DIALOG_EDIT,
DIALOG_EDIT_RENTVOZILA,
DIALOG_RENT,
DIALOG_BANK_MAIN,
DIALOG_CREATE_BANK,
DIALOG_EDIT_BANK,
DIALOG_EDIT_ATM,
DIALOG_ATM
};
Is it going to effect speed and preformance?? Should i leave them like that or should i
?? What do you think
Re: Wut?? - WhiteGhost - 27.08.2016
Its fine.
I even prefer using an enum for the dialogs but its your choice.
Re: Wut?? -
Micko123 - 27.08.2016
Well i had to ask because it is first time for me seeing dialogs like this so i was confused
Re: Wut?? -
Kwarde - 27.08.2016
When using enumerators, your compiled script will create constants (variables) which are automatically signed with an ID.
Defines however are only applied by the
pre- compiler. Before pawncc actually compiles, te pre-compiler finds every macro and changes it with it's value.
Meaning that this:
PHP код:
#define MyNumber 10
#define Add 5
main()
{
printf("MyNumber is %d. Add %d and we get: %d", MyNumber, Add, MyNumber + Add);
return 1;
}
Actually compiles like this:
PHP код:
main()
{
printf("MyNumber is %d. Add %d and we get: %d", 10, 5, 10+5);
return 1;
}
Now, if you'd use a script with enumerators:
PHP код:
#include <a_samp>
enum MyEnum
{
MyNumber,
Add
};
new var[MyEnum];
main()
{
var[MyNumber] = 10;
var[Add] = 5;
printf("MyNumber is %d. Add %d and we get: %d", var[MyNumber], var[Add], var[MyNumber] + var[Add]);
return 1;
}
This script does exactly the same, except that the compiled script will look something like this:
PHP код:
new var01, var02;
main()
{
var01 = 10;
var02 = 5;
printf("MyNumber is %d. Add %d and we get: %d", var01, var02, var01 + var02);
return 1;
}
This means that memory is used (every variable uses atleast 4 cells of the memory).
p.s.
The compiled file of the define version was (with a_samp included); 218 bytes
The compiled file of the enumerator version was (also with a_samp included); 246 bytes
Imagine that with a huge gamemode. You'd safe quite some memory using defines.