Raised This Month: $51 Target: $400
 12% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
karaulov
Senior Member
Join Date: Jul 2018
Old 10-14-2021 , 23:46   Error in AMX MOD X: Static variable is not a static!
Reply With Quote #1

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)
karaulov is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 10-15-2021 , 00:01   Re: Error in AMX MOD X: Static variable is not a static!
Reply With Quote #2

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.
__________________
My plugin:

Last edited by Celena Luna; 10-15-2021 at 00:04.
Celena Luna is offline
Old 10-15-2021, 03:16
HamletEagle
This message has been deleted by HamletEagle.
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-15-2021 , 06:23   Re: Error in AMX MOD X: Static variable is not a static!
Reply With Quote #3

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.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-15-2021 at 06:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-15-2021 , 23:43   Re: Error in AMX MOD X: Static variable is not a static!
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
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.
__________________
fysiks is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-16-2021 , 09:32   Re: Error in AMX MOD X: Static variable is not a static!
Reply With Quote #5

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.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-16-2021 , 09:57   Re: Error in AMX MOD X: Static variable is not a static!
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
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.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:51.


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