25.07.2015, 12:49
Vince is right, use globals only if you need them otherwise use locals
To your example the first is faster because the variables are only created / deleted once and inside the loop they would be created 100 times
Thats the reason why there is the first space to create the loop variable for the "for loop"
You could also rewrite a for loop to something like that
But in OnPlayerUpdate I would use static variables (these are global variables limited to the function)
Because you shouldn't create variables inside a fast repeating code like OnPlayerUpdate or loops
To your example the first is faster because the variables are only created / deleted once and inside the loop they would be created 100 times
Thats the reason why there is the first space to create the loop variable for the "for loop"
You could also rewrite a for loop to something like that
pawn Code:
function()
{
// for(statement 1; statement 2; statement 3)
{ // limit the scoop of the variables to the loop
new i, id, id2, id3; // statement 1
while(i < 100) // statement 2
{
// CODE
i++; // statement 3
}
}
}
Because you shouldn't create variables inside a fast repeating code like OnPlayerUpdate or loops