local or global variable in a timer/Using enum as integer
#7

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
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
        }
    }
}
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
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)