Quote:
Originally Posted by DJEarthQuake
I would have made it new const instead of a variable.
From the Pawn manual. I do know Amxx has it's own nuisances since it relates to the GoldSrc HLDS but you were bringing up defines.
|
A constant is by definition, well, constant. It doesn't matter that it gets replaced with its value because that value is the same value all the time.
For example:
PHP Code:
#define something 5
native_1(something)
native_2(something)
translates to
PHP Code:
native_1(5)
native_2(5)
BUT a native call is not a constant, it will return a different value on different calls.
PHP Code:
#define something create_entity("")
native_1(something)
native_2(something)
Will translate into
PHP Code:
native_1(create_entity(""))
native_2(create_entity(""))
and here each call to create_entity will return a different entity index, therefore resulting in native_1 and native_2 being applied to different entities. So, for example, at a run you may end up with:
PHP Code:
native_1(134)
native_2(135)
//2 different ent indexes.
Quote:
Originally Posted by DJEarthQuake
Static won't even compile! lol I was in the wrong directory from force of habit. I meant new const instead of static. Macros do chump a bit but few maps use this ent and only custom ones at that. So like an array repeats everything in it when applied to a native like giving a weapon in this case, you are illustrating by using this as a macro it is a memory chewer? I would have not used a macro beyond small requests and only this one because do not feel comfortable sharing script flat out disabling the USP silently. Thanks for chiming in. Please help me understand further if this is so. Have any supporting documentation or evidence beyond I said so? I need to see this. I pasted what the manual shows on GitHub today.
|
static WILL compile. But it's wrong to use static, it should be new. "static" should be used when you need a global-like variable but with local scope(limited to the function that defines the static variable). This is useful when you want to remember the value of the variable between multiple function call(like a global) but you don't want other functions to be able to change that variable.
precache is called only once, you don't need a static variable. You can use it, but you don't need it. Use "new".
It isn't a memory chewer. A macro isn't a variable. Macros do text based replacement(find and replace from word or notepad if it helps you visualize). Because of that, they have some quirks and if you aren't aware of how they work, you can end up with horribly hard to debug bugs and wrong code. In which way would it be wrong? It depends: wrong output, wasting memory, crashing, who knows. One thins is for sure: the plugin will not work as expected.
Here is an example of such a bug:
PHP Code:
#define square(%1) %1 * %1
You would expect this macro to output x * x for input x. So if you did square(5) to get back 25. But look what happens when you use it in the following way:
PHP Code:
new a = 5
square(a + 3) = a + 3 * a + 3 = a + 3a + 3 = 4a + 3
So square(a + 3) = square(5 + 3) = square( 8 ) = 4 * 8 + 3 = 35. But the square of 8 is 64. This is because it did a textual replacement of x with a + 3. It did not firstly evaluate a + 3 to 8 and then do 8 * 8, like a function would do.
Macros are parsed before the code is actually compiled. They don't make it into the final binary. Macros are not functions. Macros are not variables.
__________________