AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Bitsum question (https://forums.alliedmods.net/showthread.php?t=328385)

Shadows Adi 11-07-2020 03:35

Bitsum question
 
Hello,
I was wondering why compiler is throwing this errors:
PHP Code:

D:\Custom Projects\Zombie Apocalypse\scripting\Special_Project_ZA.1.0.sma(127 -- 128) : error 012invalid function callnot a valid address
D
:\Custom Projects\Zombie Apocalypse\scripting\Special_Project_ZA.1.0.sma(128) : error 001expected token";"but found ")"
D:\Custom Projects\Zombie Apocalypse\scripting\Special_Project_ZA.1.0.sma(128) : error 029invalid expressionassumed zero
D
:\Custom Projects\Zombie Apocalypse\scripting\Special_Project_ZA.1.0.sma(128) : fatal error 107too many error messages on one line 

I have defined macro like this
PHP Code:

#define SetBit(%1,%2) (%1 |= (1 << (%2 & 31))) 

Error is thrown only when the code is written like this:
PHP Code:

        g_bLastZombie true
        SetBit
(g_bitIsLastZombieiPlayer

when I change the position of the bit like this:
PHP Code:

        SetBit(g_bitIsLastZombieiPlayer)
        
g_bLastZombie true 

compiler is happy, I can't find a concrete explanation for this.

And btw, when I change the macro like this:
PHP Code:

#define SetBit(%1,%2) %1 |= (1 << (%2 & 31)) 

it's working in both ways.

Black Rose 11-07-2020 09:43

Re: Bitsum question
 
Seems like the compiler sees the parentheses and therefor assumes the previous is a function to be called.
Exactly like this also works:
Code:
    server_print     ("");

It could be negated by removing the parentheses as you did, adding a semicolon before it or on the end of the row before or by using it after another function.

Code:
    g_bLastZombie = true;     SetBit(g_bitIsLastZombie, iPlayer)
Code:
    g_bLastZombie = true     ;SetBit(g_bitIsLastZombie, iPlayer)
Code:
    register_plugin("Test Plugin 1", "1.0", "[ --{-@ ]")     SetBit(g_bitIsLastZombie, iPlayer)

Or simply turning it into a real function, unless called every server frame it really doesn't matter.
Code:
stock SetBit(container,bit) {     container |= ( 1 << ( bit & 31 ) ); }



But being honest here, using bitsum for setting a value for a single player that is reset when not applicable anymore without adding another player is just making things complicated. Better to just do:
Code:
g_LastZombie = iPlayer.


All times are GMT -4. The time now is 15:40.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.