Raised This Month: $ Target: $400
 0% 

This doesn't work: create_entity(const name[])


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 01-19-2007 , 16:17   This doesn't work: create_entity(const name[])
Reply With Quote #1

This works:
Code:
#include <amxmodx> #include <engine> #define DEFINED_CLASSNAME "info_target" public some_function() {     create_entity(DEFINED_CLASSNAME) }

This gives me an error: "Error: Argument type mismatch (argument 1) on line 8"

Code:
#include <amxmodx> #include <engine> new const const_classname[] = "info_target" public some_function() {     create_entity(const_classname) }

I want to use a constant instead of a define. According to the optimization AMWiki, it's a better choice.

This problem doesn't exist in the fakemeta equivalent of this function, however.

Any ideas? (Besides switching to fakemeta.)
stupok is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 01-19-2007 , 16:23   Re: This doesn't work: create_entity(const name[])
Reply With Quote #2

This compiled with 0 Errors, 0 Warnings. Don't know if you would want to use it though.

Code:
static const_classname[] = "info_target" public some_function() {     create_entity(const_classname) }
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
stupok
Veteran Member
Join Date: Feb 2006
Old 01-19-2007 , 16:35   Re: This doesn't work: create_entity(const name[])
Reply With Quote #3

Could you explain the difference between declaring const_classname[] with "static" vs. "new"?
stupok is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 01-19-2007 , 16:46   Re: This doesn't work: create_entity(const name[])
Reply With Quote #4

http://wiki.amxmodx.org/index.php/Op...atic_vs_Global

Quote:
A variable declared with the keyword "static" instead of "new" operates in the same way a global does (it is created only once) but the variable is local to the function; this means the code is much easier to read, while drastically improving speed just like a global variable.
The only thing I am unsure about is if it will act globally since I haven't tested it. It probably will though.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 01-19-2007 , 18:45   Re: This doesn't work: create_entity(const name[])
Reply With Quote #5

Look at the prototype:
native create_entity(szClassname[]);

It's not a
native create_entity(const szClassname[]);

That is why you should not use const keyword for your global. Just omit it in your example.

Using static has no sense here because of a global scope. AFAIK, global static vars are used to deny amx/x engine to access this var. It's hard to imagine for me an example when it's vital to use static declaration in global scope.
Simon Logic is offline
Send a message via Skype™ to Simon Logic
VEN
Veteran Member
Join Date: Jan 2005
Old 01-20-2007 , 04:11   Re: This doesn't work: create_entity(const name[])
Reply With Quote #6

FYI we have a report for such issues: [*.inc] Unable to pass a constant arrays to some of the functions
VEN is offline
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 22:21.


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