Tips & Tricks
#1

hey,
I thought I'd share a couple things that I use/find useful a lot when it comes to SA-MP scripting.

I'll probably add a bunch of stuff to this topic. If you have anything to contribute, let me know!

Current topics I'll be discussing:
  • The ternary operator
  • Simple int -> bool conversion
  • Fastest string loop
  • Fastest plain player-loop
  • Short functions
  • Multiple actions in one statement
  • Running code just after a function finishes
  • Getting rid of stupid tag warnings
  • "Char-arrays"
  • Split up numeric literals
  • Bit-flags in enums (advanced)
  • Using logical operators for tiny if-statements (advanced)
  • Efficient memory management with stock const (advanced)
The ternary operator
The ternary operator is an operator that takes 3 arguments; if the first argument is true then the argument right next to it will be used, if not then the last argument will be used.

The structure of the operator is this:
condition ? true : false

Here are a couple of examples:
pawn Code:
if ( a == b )
    c = d;
else
    c = e;
With the ternary operator:
pawn Code:
c = ( a == b ) ? d : e;
//   if-^   then-^   ^-else
A couple examples:
pawn Code:
SetPlayerColor( playerid, ( Team[ playerid ] == TEAM_ONE ) ? COLOR_RED : COLOR_BLUE );
// Set the color to red if the player is in TEAM_ONE, otherwise set it to blue.

GivePlayerWeapon( playerid, ( IsMadnessEnabled() ) ? WEAPON_MINIGUN : WEAPON_FLOWER, 5000 );
// If IsMadnessEnabled is true, give the player a minigun!

public OnPlayerSpawn( playerid )
{
    SetPlayerHealth( playerid, ( IsSuddenDeathEnabled() ) ? 1.0 : 100.0 );
   
    if ( ( IsPlayerAdmin( playerid ) ) ? SetPlayerPos( playerid, AdminSpawnX, AdminSpawnY, AdminSpawnZ ) : SetPlayerPos( playerid, PlayerSpawnX, PlayerSpawnY, PlayerSpawnZ ) ){}
    // I have to wrap this inside an if statement to avoid getting a warning from the PAWN compiler!
}

file = fopen( ( useSpecialFile ) ? ("special_file.txt") : ("normal_file.txt") );
// Strings need parentheses around them or the PAWN compiler will generate an error.

// You can also use ternary operators inside ternary operators!
file = fopen( ( useFile == 1 ) ? ("file1.txt") : ( ( useFile == 2 ) ? ("file2.txt") : ( ( useFile == 3 ) ? ("file3.txt") : ("file0.txt") ) ) );

// ..let's break that down
    new File:file = fopen(
        ( useFile == 1 ) ? ("file1.txt")
            : ( ( useFile == 2 ) ? ("file2.txt")
                : ( ( useFile == 3 ) ? ("file3.txt")
                    : ("file0.txt") ) )
    );
Simple int -> bool conversion
Sometimes you end up having to convert an int to a bool, the proper way to do that would be:
pawn Code:
new myInt = 50;
new bool:myBool = !!myInt;
This will make myBool become 0 if myInt equals 0, otherwise 1.
Fastest string loop
This is, by my experience, the fastest way to loop through a string.

pawn Code:
for ( new i, l = strlen( string ); i != l; i++ )
{
    // ..
}
Fastest plain player-loop
Note that foreach is faster than this - that's why the heading says plain player-loop.

pawn Code:
for ( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) )
        continue;
   
    // code for connected players
}
Short functions
If your function has only one statement - you can declare them like this:
pawn Code:
stock SomeFunction( someInput )
    return someArray[ someInput / 2 ];
Multiple actions in one statement
Statements in programming are what you'd call instructions - in PAWN these statements are all separated by the semicolon ( ; ). Sometimes you want to fit code on only one line for some reason, here's how you do that:
pawn Code:
stock KickEx( playerid, reason[] )
    SendClientMessage( playerid, 0xC00000FF, "You got kicked!! Reason:" ), SendClientMessage( playerid, 0xC00000FF, reason ), Kick( playerid );
// Sends the two client messages then kicks the player.

stock DoStuff( playerid )
    return DoFirstThing( playerid ), DoSecondThing( playerid ), DoThirdThing( playerid ), DoLastThing( playerid );
// DoStuff will return what DoLastThing returns.

public OnPlayerRequestSpawn( playerid )
{
    if ( !IsPlayerLoggedIn( playerid ) )
        return SendClientMessage( playerid, 0xC00000FF, "You're not logged in!" ), 0;
    // Send the client message and return 0
   
    return 1;
}
Running code just after a function finishes
This really isn't anything special, but I just thought I'd mention it as I haven't seen a lot of people do this.
I simply set a timer on 0 ms with no repeat somewhere and that function will be called almost right after the current function finished.

Why?
Sometimes you want to run code right after the current function finishes, here's a short example of a really handy function:
pawn Code:
stock DBResult:db_query_ex( DB:db, query[ ], bool:storeResult = true )
{
    new DBResult:dbrResult = db_query( db, query );
   
    if ( dbrResult )
    {
        if ( storeResult )
            SetTimerEx( "db_query_ex_free", 0, false, "i", _:dbrResult );
        else
            db_free_result( dbrResult );
    }
   
    return dbrResult;
}

forward db_query_ex_free( DBResult:dbrResult );
public  db_query_ex_free( DBResult:dbrResult )
    db_free_result( dbrResult );

// EXAMPLE:

public OnFilterScriptInit( )
{
    new DB:db, DBResult:dbrResult, buffer[ 16 ];
   
    db = db_open( "test.db" );
   
    dbrResult = db_query_ex( db, "SELECT 50" );
   
    db_get_field( dbrResult, 0, buffer, sizeof( buffer ) - 1 );
   
    print( buffer );
   
    // Even if the script would get some sort of error and abort running the current function,
    // the result will still get freed so you won't have a memory leak!
}
Using IsPlayerAdmin inside OnRconLoginAttempt doesn't work - the admin-status is set after that function executes. Example:
pawn Code:
new
    bool:g_IsRconAdmin[ MAX_PLAYERS ]
;

public OnPlayerConnect( playerid )
    g_IsRconAdmin[ playerid ] = false;

public OnRconLoginAttempt( ip[ ], password[ ], success ) // IsPlayerAdmin returns false if you check it inside this function. :(
    SetTimer( "CheckNewRconAdmins", 0, false );

forward CheckNewRconAdmins( );
public  CheckNewRconAdmins( )
{
    for ( new slots = GetMaxPlayers( ), playerid; playerid < slots; playerid++ )
    {
        if ( !g_IsRconAdmin[ playerid ] && IsPlayerAdmin( playerid ) )
        {
            // IsPlayerAdmin always returns false for unconnected players so we can save some performance by only calling that function.
           
            OnPlayerRconLogIn( playerid );
           
            break;
            // There should be at most new admin each function call, so we can break out of the loop now.
        }
    }
}

OnPlayerRconLogIn( playerid )
{
    SendClientMessage( playerid, 0x0000C0FF, "Welcome, Mr. Rcon!" );
}
Here's a part of a post by Y_Less explaining how he uses this:
Quote:
Originally Posted by Y_Less
View Post
I find this useful to apply a large set of operations at once. If you look in the YSI library YSI_td.own it can dynamically update textdraws, so you can move them about the screen or change the colour etc. If you have code which looks like this:

pawn Code:
TD_Colour(td, 0xFF0000AA);
TD_SetShadow(td, 3);
TD_Font(td, 2);
That will change the textdraw for anyone looking at it to a red style 2 TD with a shadow, however because of the way the system used to work that would have redrawn the textdraw three times when it doesn't need to. The old method of fixing this was an extra parameter:

pawn Code:
TD_Colour(td, 0xFF0000AA, false);
TD_SetShadow(td, 3, false);
TD_Font(td, 2);
So only the last update in a set would change the appearance, the new system however uses a timer in much the same way as you just described. All the functions contain this (or something similar):

pawn Code:
if (YSI_g_sTimer[td] == -1)
{
    YSI_g_sTimer[td] = SetTimerEx("TD_Delay", 0, 0, "i", td);
}
That way the "TD_Delay" function is always called after the last current update is applied, without knowing a user's code in advance.
Getting rid of stupid tag warnings
When putting Text3Ds, DBResults, and stuff inside functions such as printf, format, SetTimerEx, CallLocalFunction, CallRemoteFunction you might notice you're getting a tag warning.
You're not doing anything wrong!
What you do to get rid of them is you clear the tag - clearing the tag is done by putting an underscore as a tag.
Example:
pawn Code:
new Text3D:t3dTest = Create3DTextLabel( .. ), Text:txTest = TextDrawCreate( .. );

printf( "DEBUG: %d, %d", _:t3dTest, _:txTest );
"Char-arrays"
PAWN has a feature for accessing single bytes in arrays, intended for use with packed strings. Most SA-MP natives doesn't cover packed strings, though.
You can, however, utilize these arrays a lot for memory optimization. A normal array can store values between -2,147,483,648 and 2,147,483,647; you don't always need that capacity, do you?
With packed strings you can store values between 0-255 (yes, no negative values; -1 will wrap to 255). When you know you don't need negative values and won't ever exceed 255, why not save some memory?

pawn Code:
new bool:g_IsPlayerSomething[ MAX_PLAYERS ]; // 500 cells * 4 bytes per cell = 2000 bytes!
new bool:g_IsPlayerSomething[ MAX_PLAYERS char ]; // 500 bytes = .. 500 bytes!
If you use "char arrays" instead of normal ones where needed 50 times you'll save 75,000 bytes (~73 kb).

Note!
When accessing these arrays, you need to use curly brackets (aka braces) as opposed to the normal square brackets.
Example:
pawn Code:
public OnPlayerConnect( playerid )
{
    g_IsPlayerSomething{ playerid } = false;
//                     ^          ^
}

public OnPlayerSpawn( playerid )
{
//                          v          v
    if ( g_IsPlayerSomething{ playerid } )
    {
        // ..
    }
}
Split up numeric literals
Quote:
Originally Posted by Y_Less
View Post
A very small thing I found out the other day, you can split up long numeric literals in a similar way to how you do in maths. Normal writing:

Code:
345,234,148
Here "," is used as a thousands separator (sometimes "." I believe, but PAWN uses that for decimal). You can also do this in PAWN using "'" instead:

pawn Code:
345'234'148
And you can split HEX numbers up every 4, or binary numbers every 8:

pawn Code:
0x12FD'39C5
0b00000000'
11111111'01010101
As you can see, the highlighter doesn't like this.
Bit-flags in enums
Did you know that you can store 32 true/false values in one single variable? Not only do you save space, but you also get less clutter in your code.

You don't have to understand how the binary numeral system works; however, I recommend it. You can read more about it in this topic, if you're interested.

If you have, say, 100 true/false (bool) per-player variables you would use 195 KB of space. However, if you were to use 4 arrays with bit flags, only 8 KB of space would be used. The outcome would be exactly the same, but you would save 187 KB of space!

Here's an example also containing macros to simplify the usage.
pawn Code:
// Usage for all macros: BitFlag_X(variable, flag)
#define BitFlag_Get(%0,%1)            ((%0) & (%1))   // Returns zero (false) if the flag isn't set.
#define BitFlag_On(%0,%1)             ((%0) |= (%1))  // Turn on a flag.
#define BitFlag_Off(%0,%1)            ((%0) &= ~(%1)) // Turn off a flag.
#define BitFlag_Toggle(%0,%1)         ((%0) ^= (%1))  // Toggle a flag (swap true/false).

enum PlayerFlags:(<<= 1) {
    // It's important that you don't forget to put "= 1" on the first flag. If you don't, all flags will be 0.
   
    PLAYER_IS_LOGGED_IN = 1,   // 0b00000000000000000000000000000001
    PLAYER_HAS_GANG,           // 0b00000000000000000000000000000010
    PLAYER_CAN_BUY_PROPERTIES, // 0b00000000000000000000000000000100
    PLAYER_BLABLA_1,           // 0b00000000000000000000000000001000
    PLAYER_BLABLA_2,           // 0b00000000000000000000000000010000
    PLAYER_BLABLA_3,           // 0b00000000000000000000000000100000
    PLAYER_BLABLA_4,           // 0b00000000000000000000000001000000
    PLAYER_BLABLA_5,           // 0b00000000000000000000000010000000
    PLAYER_BLABLA_6,           // 0b00000000000000000000000100000000
    PLAYER_BLABLA_7,           // 0b00000000000000000000001000000000
    PLAYER_BLABLA_8,           // 0b00000000000000000000010000000000
    PLAYER_BLABLA_9,           // 0b00000000000000000000100000000000
    PLAYER_BLABLA_10,          // 0b00000000000000000001000000000000
    PLAYER_BLABLA_11,          // 0b00000000000000000010000000000000
    PLAYER_BLABLA_12,          // 0b00000000000000000100000000000000
    PLAYER_BLABLA_13,          // 0b00000000000000001000000000000000
    PLAYER_BLABLA_14,          // 0b00000000000000010000000000000000
    PLAYER_BLABLA_15,          // 0b00000000000000100000000000000000
    PLAYER_BLABLA_16,          // 0b00000000000001000000000000000000
    PLAYER_BLABLA_17,          // 0b00000000000010000000000000000000
    PLAYER_BLABLA_18,          // 0b00000000000100000000000000000000
    PLAYER_BLABLA_19,          // 0b00000000001000000000000000000000
    PLAYER_BLABLA_20,          // 0b00000000010000000000000000000000
    PLAYER_BLABLA_21,          // 0b00000000100000000000000000000000
    PLAYER_BLABLA_22           // 0b00000001000000000000000000000000
};

new
    // Create an array with the same tag as the enum
    PlayerFlags:g_PlayerFlags[MAX_PLAYERS]
;

public OnPlayerConnect(playerid) {
    // 0 - All flags are off (false). You must include the tag to prevent a warning.
    g_PlayerFlags[playerid] = PlayerFlags:0;
}

public OnPlayerLogIn(playerid) {
    BitFlag_On(g_PlayerFlags[playerid], PLAYER_IS_LOGGED_IN);
   
//  Without macros:
//  g_PlayerFlags[playerid] |= PLAYER_IS_LOGGED_IN;
}

public OnPlayerJoinGang(playerid) {
    BitFlag_On(g_PlayerFlags[playerid], PLAYER_HAS_GANG);
   
//  Without macros:
//  g_PlayerFlags[playerid] |= PLAYER_HAS_GANG;
}

public OnPlayerLeaveGang(playerid) {
    BitFlag_Off(g_PlayerFlags[playerid], PLAYER_HAS_GANG);
   
//  Without macros:
//  g_PlayerFlags[playerid] &= ~PLAYER_HAS_GANG;
}

public OnPlayerUpdate(playerid) {
    // DoSomething every-other player update.
   
    BitFlag_Toggle(g_PlayerFlags[playerid], PLAYER_BLABLA_19);
   
    if (BitFlag_Get(g_PlayerFlags[playerid], PLAYER_BLABLA_19)) {
        DoSomething();
    }
   
//  Without macros:
//  g_PlayerFlags[playerid] ^= PLAYER_BLABLA_19;
// 
//  if (g_PlayerFlags[playerid] & PLAYER_BLABLA_19) {
//      DoSomething();
//  }
}
Using logical operators for tiny if-statements
You can use logical operators as if-statements, but do it all inside one single statement!

For example, I wrote a fixed version of valstr and I did it like this without thinking too much about it:
pawn Code:
stock FIXES_valstr(dest[], value, bool:pack = false)
{
    static const cellmin_value[] = !"-2147483648";

    if (value == cellmin)
        pack && strpack(dest, cellmin_value, 12) || strunpack(dest, cellmin_value, 12);
    else
        format(dest, 12, "%d", value), pack && strpack(dest, dest, 12);
    // Notice the comma after format? See the section "Multiple actions in one statement" in this topic.
}
As you can see, there are logical operators (&& and ||) just out in the open.

The code above, without this little trick, would look something like this:
pawn Code:
stock FIXES_valstr(dest[], value, bool:pack = false)
{
    static const cellmin_value[] = !"-2147483648";

    if (value == cellmin) {
        if (pack)
            strpack(dest, cellmin_value, 12)
        else
            strunpack(dest, cellmin_value, 12);
    } else {
        format(dest, 12, "%d", value);
       
        if (pack)
            strpack(dest, dest, 12);
    }
}
A few examples:
pawn Code:
a && b();              // if a, run b.
a && b() || c();       // if a, run b. otherwise, run c.
a || b();              // if not a, run b.
a && b() || c && d();  // if a, run b. otherwise, if c, run d.
a && b() && c();       // if a, run b. if b isn't false, run c.
Efficient memory management with stock const
Written by Y_Less.

"stock const".

This is something I discovered a while ago, but forgot to ever write up:

pawn Code:
#include <a_samp>

main()
{
    print("hi");
    print("hi");
}
If we compile this with "-a" we get:

Code:
CODE 0	; 0
;program exit point
	halt 0

	proc	; main
	; line 4
	; line 5
	push.c 0
	;$par
	push.c 4
	sysreq.c 0	; print
	stack 8
	;$exp
	; line 6
	push.c c
	;$par
	push.c 4
	sysreq.c 0	; print
	stack 8
	;$exp
	zero.pri
	retn


DATA 0	; 0
dump 68 69 0 68 69 0 

STKSIZE 1000
I have highlighted two lines in bold. The first pushes the number "0", the second pushes the number "12" ("c"). "print", for it's first (and only) parameter, takes the address of a string to print. All string literals are converted to data and stored in global memory (I won't go in to the details of the true implications of this, but sufficed to say you change them). "dump" is the current global memory for this tiny program:

Code:
dump 68 69 0 68 69 0
If we convert those numbers to ascii we suddenly see:

Code:
dump 'h' 'i' '\0' 'h' 'i' '\0'
I.e. our two "hi" strings - two copies of the same string isn't very efficient though, so let's improve this by explicitly managing the memory:

pawn Code:
#include <a_samp>

stock const
    C_HI[3] = "hi";

main()
{
    print(C_HI);
    print(C_HI);
}
Code:
CODE 0	; 0
;program exit point
	halt 0


DATA 0	; 0
dump 68 69 0 

	proc	; main
	; line 7
	; line 8
	push.c 0
	;$par
	push.c 4
	sysreq.c 0	; print
	stack 8
	;$exp
	; line 9
	push.c 0
	;$par
	push.c 4
	sysreq.c 0	; print
	stack 8
	;$exp
	zero.pri
	retn


STKSIZE 1000
The location of "dump" has changed, but that's not important - a large program will have many "dump" statements spread throughout its code, all combined in the final stages of compilation. The important things to look at are the contents of "dump" and the two highlighted lines.

Despite the fact that we are using a variable, this is still EXACTLY as efficient code-wise as the original version because we are still using constant strings. However, the memory requirements for storing the two strings has halved, with both instances pointing to the same memory.

You can also use "new const" or "static stock const", but "stock const" is probably best for this code to avoid warnings and dupilcation of the memory we are trying not to duplicate.

Your assembly output will probably look different if you are not using "-d0".
Reply
#2

Thanks for posting..
I had personally forgotten about some of these, just learned a few more, and knew a few as well.
Great post nonetheless.
Reply
#3

Thank you for the ternary and IntBool examples.
Reply
#4

thanks for these!
Reply
#5

Wow,nice tut xD
Reply
#6

The ternary operator is called the triadic operator on the wiki.
I don't know what its real name is, but I've been using it for quite a while and it's very useful.

Also, something I have been doing lately is using packed arrays for player vars.
These are 1/4th of the size of a regular array and work just as good.

Example:
pawn Code:
new
    SomePlayerVar[MAX_PLAYERS char];

// This will create an array with 125 cells, instead of 500
// To use:

SomePlayerVar{playerid} = 1;

if(SomePlayerVar{playerid})
{
    // do stuff
}
The only downside: You can't store a value greater than 254 (defined as charmax) in it, but it's great if you only need to store true (1) or false (0) or something.
Reply
#7

It's nice/usefull blabla. Thanks. I think I can use the things that I didn't use yet :')
Reply
#8

Thank you for your contribution, Slice! Hopefully most of this stuff will come in handy for me.
Reply
#9

@Vince: In maths ternary/triadic relations are the same things. I don't often see the operator referred to as a triadic operator very often, however.
Covering the packed strings sounds like a good idea, I use those all the time for bit flags and small values. I'll see what I can come up with. The max value is 255, actually (0 - FF).

Edit: Added a section on this at the bottom.
Reply
#10

Very useful!
Reply
#11

Good Work Slice :3


But use ++i and not i++...


Great Tutorial!
Reply
#12

Quote:
Originally Posted by [FeK]DraKiNs
View Post
Good Work Slice :3


But use ++i and not i++...


Great Tutorial!
++x and x++ statements that aren\'t inside anything are exactly the same thing in PAWN. If the value is used, the only difference is that 2 assembly instructions happen in a different order.
Reply
#13

I\'ve been using the ternary operator for quite some time now (Can be found in my turtle/cow scripts for those who looked at the source), it\'s really great. Something else what is fun to do with it is to make complex code (Preferably a ternary operator inside a ternary operator), then break your head on what is actually stated haha.


I didn\'t knew about the char arrays either, I\'m sure to use this in the future along with other functions.
Reply
#14

just watched your "fastest loops" section -

still too long, the steps that make you feel good

are useless, you can directly do i < GetMaxPlayers() f.e.
Reply
#15

@Hiddos:
pawn Code:
for(new i,s[64];i<10;i++)strcat(s,!i?("The"):i<2?("quick"):i<3?("brown"):i<4?("fox"):i<5?("jumps"):i<6?("over"):i<7?("the"):i<8?("lazy"):i<9?("dog."):i<printf(s)?(""):("")),strcat(s," ");
wat


Quote:
Originally Posted by Trooper[Y]
View Post
just watched your "fastest loops" section -

still too long, the steps that make you feel good

are useless, you can directly do i < GetMaxPlayers() f.e.
Oh and call GetMaxPlayers every iteration? You do that!
Reply
#16

Quote:
Originally Posted by Slice
View Post
@Hiddos:
pawn Code:
for(new i,s[64];i<10;i++)strcat(s,!i?("The"):i<2?("quick"):i<3?("brown"):i<4?("fox"):i<5?("jumps"):i<6?("over"):i<7?("the"):i<8?("lazy"):i<9?("dog."):i<printf(s)?(""):("")),strcat(s," ");
pawn Code:
for(new i, s[64]; i < 10; i++)
{
    if(!i) strcat(s, "The"), strcat(s, " ");
    else if(i < 2) strcat(s, "quick"), strcat(s, " ");
    else if(i < 3) strcat(s, "brown"), strcat(s, " ");
    else if(i < 4) strcat(s, "fox"), strcat(s, " ");
    else if(i < 5) strcat(s, "jumps"), strcat(s, " ");
    else if(i < 6) strcat(s, "over"), strcat(s, " ");
    else if(i < 7) strcat(s, "the"), strcat(s, " ");
    else if(i < 8) strcat(s, "lazy"), strcat(s, " ");
    else if(i < 9) strcat(s, "dog."), strcat(s, " ");
    else if(i < printf(s)) strcat(s, ""), strcat(s, " ");
    else strcat(s, ""), strcat(s, " ");
}


Did a test, it worked. I\'m a genius.

I also found this in some code of a script of mine. It unfortunately did not work. I\'m still thinking of disassembling it once ^^.

Code:
Pos[0] += ((Keys[2] > 0) ? ((Keys[0] & KEY_SPRINT) ? ((Keys[0] & KEY_JUMP) ? (5.4) : (3.6)) : ((Keys[0] & KEY_JUMP) ? (2.7) : (1.8))) : (Keys[2] < 0) ? ((Keys[0] & KEY_SPRINT) ? ((Keys[0] & KEY_JUMP) ? (-5.4) : (-3.6)) : ((Keys[0] & KEY_JUMP) ? (-2.7) : (-1.8))) : (0.0));
Good luck if anyone feels like trying it. The ( ) should be of much help ^^.
Quote:
Originally Posted by Slice
View Post
Oh and call GetMaxPlayers every iteration? You do that!
Hmm, doesn\'t sound like a perfect method ^^.
Reply
#17

@Trooper[Y]

What?

pawn Code:
for(new i; i < GetMaxPlayer(); ++i)
is not otimized,lol

@Slice

I know what

i++ keeping the value in memory, and only applies to the variable after the instruction has been executed, the ++i apply at the time of instruction without storing in memory.


Not?
Reply
#18

@Hiddos:

Put this in a FS and load it.
pawn Code:
#include <a_samp>

public OnFilterScriptInit()
for(new c[]="osudrlnfaYAI tvciy\'mW
gwehk"
,i=2,s[146],y[2];i>1;i++)
y[0]=c[i<3?21:i<4?21:i<5?21:i<6?20:i<7?24:i<8?18:i<9?4:i<10?24:i<11?12:i<12?6:i<13?0:i<14?12:i<15?1:i<16?13:i<17?4:i<18?8:i<19?6:i<20?22:i<21?24:i<22?4:i<23?1:i<24?12:i<25?13:i<26?0:i<27?12:i<28?5:i<29?0:i<30?14:i<31?24:i<32?21:i<33?9:i<34?0:i<35?2:i<36?12:i<37?26:i<38?6:i<39?0:i<40?23:i<41?12:i<42?13:i<43?25:i<44?24:i<45?12:i<46?4:i<47?2:i<48?5:i<49?24:i<50?1:i<51?12:i<52?8:i<53?6:i<54?3:i<55?12:i<56?1:i<57?0:i<58?12:i<59?3:i<60?0:i<61?12:i<62?11:i<63?21:i<64?10:i<65?12:i<66?7:
i<67?2:i<68?5:i<69?5:i<70?12:i<71?15:i<72?0:i<73?19:i<74?19:i<75?16:i<76?13:i<77?19:i<78?24:i<79?6:i<80?13:i<81?18:i<82?1:i<83?12:i<84?23:i<85?25:i<86?8:i<87?13:i<88?12:i<89?11:i<90?18:i<91?19:i<92?12:i<93?13:i<94?25:i<95?16:i<96?6:i<97?26:i<98?16:i<99?6:i<100?22:i<101?12:i<102?0:i<103?7:i<104?21:i<105?9:i<106?0:i<107?2:i<108?12:i<109?23:i<110?0:i<111?2:i<112?5:i<113?3:i<114?6:i<115?18:i<116?13:i<117?12:i<118?22:i<119?24:i<120?13:i<121?12:i<122?13:i<123?25:i<124?16:i<125?1:
i<126?12:i<127?7:i<128?4:i<129?0:i<130?19:i<131?12:i<132?8:i<133?6:i<134?17:i<135?12:i<136?0:i<137?13:i<138?25:i<139?24:i<140?4:i<141?12:i<142?22:i<143?2:i<144?17:i<145?21:i<146?21:i<147?21:print(s)?(i=0):(i=0)],strcat(s,y);
Win.


Also, I broke down your ternary and noticed an error that I fixed - try this:
pawn Code:
Pos[0] +=
    (
        ( Keys[2] > 0 )
        ? (
            ( Keys[0] & KEY_SPRINT )
            ? (
                ( Keys[0] & KEY_JUMP )
                    ? ( 5.4 )
                    : ( 3.6 ) )
            : (
                ( Keys[0] & KEY_JUMP )
                    ? ( 2.7 )
                    : ( 1.8 ) )
        )
        : (
            ( Keys[2] < 0 )
            ? (
                ( Keys[0] & KEY_SPRINT )
                ? (
                    ( Keys[0] & KEY_JUMP )
                    ? ( -5.4 ) : ( -3.6 ) )
                : (
                    (Keys[0] & KEY_JUMP)
                    ? ( -2.7 ) : ( -1.8 ) )
            )
            : ( 0.0 )
        )
    )
;


@[FeK]DraKiNs:

In PAWN it\'s different, there\'s no difference in speed if you\'re using ++i or i++ and using its value - there is a slight difference in the resulting assembly code, though.

If you\'re not using the value from the variable you\'re incrementing (like in a for loop), ++i and i++ are the exact same things.

pawn Code:
for ( new i = 0, l = strlen( string ); i != l; i++ )
Is exactly the same as:
pawn Code:
for ( new i = 0, l = strlen( string ); i != l; ++i )


If you don\'t believe me, run the PAWN compiler with the additional -a in the command line to see the assembly output.
Reply
#19

i believe you :3
is that we\'re used to other languages ..
But Thanks Slice

Sorry my English
Reply
#20

gnagnagna Hiddos and Slice are doing the most funny match ever: The script match
Never heard of it untill now.

And @Hiddos ("I\'m a genius"):
And you\'re soooo modest xD (bescheiden)...
NOT! :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)