AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error in AMX MOD X: Static variable is not a static! (https://forums.alliedmods.net/showthread.php?t=334710)

karaulov 10-14-2021 23:46

Error in AMX MOD X: Static variable is not a static!
 
Code inside .inc

Code:

stock rm_base_plugin_id()
{
        static pluginid = -1;

        if (pluginid != -1)
        {       
                log_amx("USE STATIC! %d", pluginid);
                return pluginid;
        }
       
        new num_of_plugins = get_pluginsnum()
        for (new i = 0; i < num_of_plugins; ++i)
        {
                if (get_func_id("RM_RegisterPlugin",i) >= 0)
                {
                        pluginid = i;
                        break;
                }
        }
       
        return pluginid;
}

I need cache pluginid value for speedup. But I can't see 'USE STATIC! ' message in console.

Why static not works as I need (like in c/c++ language)

Celena Luna 10-15-2021 00:01

Re: Error in AMX MOD X: Static variable is not a static!
 
I think it should be
Code:
static pluginid; pluginid = -1;

Also you should printout pluginid when set pluginid = i to make sure it run though.

Natsheh 10-15-2021 06:23

Re: Error in AMX MOD X: Static variable is not a static!
 
Why are you pre incrementing the variable i.

I can't remember if the 0 id is being Skipped but other than that everything seems fine.

Also luna declaration of a static variable with a starting constant value is valid.


So this is valid!

PHP Code:

static pluginid = -1


Also for the OP Try using server_print instead of log_amx and see if the thing is outputted, but make sure to call the function more than once.

fysiks 10-15-2021 23:43

Re: Error in AMX MOD X: Static variable is not a static!
 
Quote:

Originally Posted by Natsheh (Post 2760657)
Why are you pre incrementing the variable i.

I can't remember if the 0 id is being Skipped but other than that everything seems fine.

The i variable isn't being evaluated for use by other code in that expression (because it's alone) so the pre- and post-incrementing is not relevant and will make no difference.

Napoleon_be 10-16-2021 09:32

Re: Error in AMX MOD X: Static variable is not a static!
 
Sounds like this block is never called

PHP Code:

if (get_func_id("RM_RegisterPlugin",i) >= 0)
{
    
pluginid i;
    break;


As mentioned already, log it and check it.

Natsheh 10-16-2021 09:57

Re: Error in AMX MOD X: Static variable is not a static!
 
Quote:

Originally Posted by fysiks (Post 2760732)
The i variable isn't being evaluated for use by other code in that expression (because it's alone) so the pre- and post-incrementing is not relevant and will make no difference.

oh i see.


All times are GMT -4. The time now is 11:31.

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