Optimizing questions
#1

I already asked this in "general minor question's", but didn't get well questions, so I'll ask it here again.

Quote:

Message originally posted by TehEbil on 04/01/2011 at 03:54 PM:

Hey, atm I'm optimizing my script, so I've got some questions:

1)
Since I know that using of functions make the script slower, I write the part of the function into the command itself, but when functions are useful? If the functions should be repeated more times? And then, it is rly better or just cleaner ?


2)
What is better and what is faster? Or What you would prefer using?
pawn Код:
new sib;

stock function()
{
     sib = ...
}
or

pawn Код:
stock function()
{
     new sib = ...
}
For sure, the second looks cleaner, but in this case, we always create a new variable instead of using the global one, so I don't understand why people do not use just one string[127] for all their [127] strings instead of always creating new one's in every 10th line... And what about static?

3)
solved

4)
Since functions are slower than defines, I try to convert my functions into defines, but there's my first error:

pawn Код:
#define AdminLog(%0,%1,%2,%3)   getdate(year2, month2, day2);   gettime(hour2, minute2, second2); format(Query, 235, "INSERT INTO `Admin Logs` (`Adminname`, `Spielername`, `Aktion`, `Grund`, `Datum`) VALUES('%s', '%s', '%s', '%s', '%d-%d-%d %d:%d:%d')", pInfo[%0][Name], pInfo[%1][Name], %3, %4, year2, month2, day2, hour2, minute2, second2); mysql_query(Query);
                               
tried this this way and:                               

#define AdminLog(%0,%1,%2,%3)   getdate(year2, month2, day2);
                                gettime(hour2, minute2, second2); \
                                format(Query, 235, "INSERT INTO `Admin Logs` (`Adminname`, `Spielername`, `Aktion`, `Grund`, `Datum`) VALUES('%s', '%s', '%s', '%s', '%d-%d-%d %d:%d:%d')", pInfo[%0][Name], pInfo[%1][Name], %3, %4, year2, month2, day2, hour2, minute2, second2); \
                                mysql_query(Query);
but same error:
warning 236: unknown parameter in substitution (incorrect #define pattern)

Line:
AdminLog(playerid, ID, "Kick", string);


5) Last question:
Is it a different between using new string[120] and string[127]? I think so, but I read somewhere that you should take the 2І, 2і, ... (-1, cause of \0) parts, is that true?

- TehEbil

edit:

6)
What is 'better'?

pawn Код:
if()
   { ... return 1; }
...

or

if()
{ ... return 1; }
else
{
...
}

or

if()
   ...
else
{
...
}

Example:

COMMAND:o(playerid, params[])
{
    IsAdmin(==0, playerid)
    new string[127];
    if(sscanf(params, "s[MAX_STRINGS]", string)) return SendClientMessage(playerid, FARBE_WEISS, "Benutze: /o [Text]");
    SendFormattedTextToAll(FARBE_WEISS, "(( %s: %s ))",pInfo[playerid][Name], string);
    return 1;
}
I read somewhere that there shall be an 'else' because the compiler does ( not ) something with it

- TehEbil

Reply


Messages In This Thread
Optimizing questions - by TehEbil - 22.01.2011, 13:15
Re: Optimizing questions - by Macluawn - 22.01.2011, 13:32
Re: Optimizing questions - by Kyosaur - 22.01.2011, 14:14
Re: Optimizing questions - by TehEbil - 22.01.2011, 14:31
Re: Optimizing questions - by Joe Staff - 22.01.2011, 14:47
Re: Optimizing questions - by TehEbil - 22.01.2011, 14:51
Re: Optimizing questions - by Kyosaur - 22.01.2011, 15:35
Re: Optimizing questions - by TehEbil - 22.01.2011, 15:48
Re: Optimizing questions - by Joe Staff - 22.01.2011, 16:47
Re: Optimizing questions - by dice7 - 22.01.2011, 17:14

Forum Jump:


Users browsing this thread: 4 Guest(s)