Question ?
#1

What mean that exemple:

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

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

Код:
// in function

new String[128];
??
Reply
#2

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;
}
Reply
#3

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)
Reply
#4

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
Reply
#5

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
Reply
#6

I gave you too +REP , thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)