SA-MP Forums Archive
Wut?? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Wut?? (/showthread.php?tid=615799)



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
PHP код:
#define DIALOG 
?? 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"MyNumberAddMyNumber Add);
    return 
1;

Actually compiles like this:
PHP код:
main()
{
    
printf("MyNumber is %d. Add %d and we get: %d"10510+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 var01var02;
main()
{
    
var01 10;
    
var02 5;
    
printf("MyNumber is %d. Add %d and we get: %d"var01var02var01 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.