AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   This doesn't work: create_entity(const name[]) (https://forums.alliedmods.net/showthread.php?t=50107)

stupok 01-19-2007 16:17

This doesn't work: create_entity(const name[])
 
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.)

Minimum 01-19-2007 16:23

Re: This doesn't work: create_entity(const name[])
 
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) }

stupok 01-19-2007 16:35

Re: This doesn't work: create_entity(const name[])
 
Could you explain the difference between declaring const_classname[] with "static" vs. "new"?

Minimum 01-19-2007 16:46

Re: This doesn't work: create_entity(const name[])
 
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.

Simon Logic 01-19-2007 18:45

Re: This doesn't work: create_entity(const name[])
 
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.

VEN 01-20-2007 04:11

Re: This doesn't work: create_entity(const name[])
 
FYI we have a report for such issues: [*.inc] Unable to pass a constant arrays to some of the functions


All times are GMT -4. The time now is 22:21.

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