SA-MP Forums Archive
Question ? - 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: Question ? (/showthread.php?tid=583624)



Question ? - Mariciuc223 - 29.07.2015

What mean that exemple:

Код:
number % 65521;
Witch it's the best ?

Код:
// below defines
new gString[128];
or

Код:
// in function

new String[128];
??


Re: Question ? - Midzi - 29.07.2015

Variable before function is global variable. It's mean that it can be used everywhere.
Variable in function is local variable. It's mean that it can be used only in this function.

Example for global:
Код:
new gString[128];

MyFunction(playerid)
{
     format(gString, sizeof gString, "ID: %d", playerid); // It can be used here
     SendClientMessage(playerid, -1, gString);

     return 1;
}

// But also here
MyFunction2(playerid)
{
     gString[0] = EOS;

     return 1;
}
For local variable:
Код:
MyFunction(playerid)
{
     new gString[128];

     format(gString, sizeof gString, "ID: %d", playerid);
     SendClientMessage(playerid, -1, gString); // It can be used here

     return 1;
}

// But not here - error: undefined symbol gString
MyFunction2(playerid)
{
     gString[0] = EOS; // Undefined symbol gString

     return 1;
}
If you using same variable (ex. string) everywhere, the best option is global variable.

Код:
MyFunction(playerid)
{
     // I must get it here

     return 1;
}

MyFunction2(playerid)
{
     // And here!

     return 1;
}
Up option is better than:
Код:
MyFunction(playerid)
{
     new gString[128];

     // Using my variable

     return 1;
}

MyFunction2(playerid)
{
     new gString[128]; // New variable! OMG!

     // Using my variable again

     return 1;
}



Re: Question ? - Battlezone - 29.07.2015

Quote:
Originally Posted by Midzi
Посмотреть сообщение
Variable before function is global variable. It's mean that it can be used everywhere.
Variable in function is local variable. It's mean that it can be used only in this function.
^ +Also avoid using global variables (under defines)


Re: Question ? - Mariciuc223 - 29.07.2015

Quote:
Originally Posted by Midzi
Посмотреть сообщение
Variable before function is global variable. It's mean that it can be used everywhere.
Variable in function is local variable. It's mean that it can be used only in this function.

Example for global:
Код:
new gString[128];

MyFunction(playerid)
{
     format(gString, sizeof gString, "ID: %d", playerid); // It can be used here
     SendClientMessage(playerid, -1, gString);

     return 1;
}

// But also here
MyFunction2(playerid)
{
     gString[0] = EOS;

     return 1;
}
For local variable:
Код:
MyFunction(playerid)
{
     new gString[128];

     format(gString, sizeof gString, "ID: %d", playerid);
     SendClientMessage(playerid, -1, gString); // It can be used here

     return 1;
}

// But not here - error: undefined symbol gString
MyFunction2(playerid)
{
     gString[0] = EOS; // Undefined symbol gString

     return 1;
}
If you using same variable (ex. string) everywhere, the best option is global variable.

Код:
MyFunction(playerid)
{
     // I must get it here

     return 1;
}

MyFunction2(playerid)
{
     // And here!

     return 1;
}
Up option is better than:
Код:
MyFunction(playerid)
{
     new gString[128];

     // Using my variable

     return 1;
}

MyFunction2(playerid)
{
     new gString[128]; // New variable! OMG!

     // Using my variable again

     return 1;
}
Quote:
Originally Posted by Battlezone
Посмотреть сообщение
^ +Also avoid using global variables (under defines)
Ok , thanks but anyone can say me what that mean :

Код:
number % 65521;
EDIT: lol , i have 68 local strings with the same name and the same cell size :O


Re: Question ? - Midzi - 29.07.2015

It means:
Код:
if(number == 65521 && number == 65521 * 2 /* and go one, and go one */)
It is a condition of valor number by 65521

Or it just:
https://sampforum.blast.hk/showthread.php?tid=485069


Re: Question ? - Mariciuc223 - 29.07.2015

I gave you too +REP , thanks