AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [REQ] Static Enums (https://forums.alliedmods.net/showthread.php?t=238059)

souvikdas95 04-03-2014 14:28

[REQ] Static Enums
 
Can AmxModX introduce support for static enums like :

Code:

public client_putinserver ( id )
{
        static enum _:TEST
        {
                iNum1 = 0,
                iNum2,
                szString[128]
        }

        new DATA[TEST];
}


GuskiS 04-03-2014 15:52

Re: [REQ] Static Enums
 
Make global?

hornet 04-03-2014 17:11

Re: [REQ] Static Enums
 
Don't XY, explain what your trying to do.

Arkshine 04-03-2014 17:52

Re: [REQ] Static Enums
 
+ I'm not sure why you're even 'requesting' something in "Scripting section". You know perfectly that's not the right place. But yes, explain yourself, you could just make the enum global.

hleV 04-05-2014 07:09

Re: [REQ] Static Enums
 
The compiler seems to be fine with function-scope enumerations, though I'm curious whether they're initialized on startup or when the function is called.

souvikdas95 04-05-2014 07:14

Re: [REQ] Static Enums
 
Uhm... Suppose I want to reuse the symbols in that enum in another function but I don't want to use that same enum or redeclaring it as many times as the function is called. So, how do I do that?
Making it global returns compilation errors saying symbol already declared or so...

@Arkshine - I have some problems with understanding where to post what :P Can you shift this thread to the required section?

Black Rose 04-05-2014 08:15

Re: [REQ] Static Enums
 
Quote:

Originally Posted by souvikdas95 (Post 2120420)
Uhm... Suppose I want to reuse the symbols in that enum in another function but I don't want to use that same enum or redeclaring it as many times as the function is called. So, how do I do that?
Making it global returns compilation errors saying symbol already declared or so...

This is the right section for this kind of post.
It's because you're trying to declare something twice. If you would've shown the real code and the real error we would be able to help you. Without that I can only tell you to change the variable names of/in the enum.
Neither of these are ok:
Code:
new Test1 enum Test1 {     Whatever } new Test2 enum Whatever2 {     Test2 }

Code:

N:\Nerladdat\! Spel\CS\! Scripting\Rose\test4.sma(4) : error 021: symbol already defined: "Test1"
N:\Nerladdat\! Spel\CS\! Scripting\Rose\test4.sma(11) : error 021: symbol already defined: "Test2"


souvikdas95 04-05-2014 08:54

Re: [REQ] Static Enums
 
hmm... so my request is valid right?

Code:

function()
{
        static enum _:test
        {
                num1,
                num2,
                name[32];
        }
        static DATA[test];
}

function2()
{
        new name[64],num1,num2;
}

I want this to be valid.

Black Rose 04-05-2014 09:00

Re: [REQ] Static Enums
 
Nope. Make the enum global. You don't have to make the DATA global though. But the difference between global and static is none I believe.

fysiks 04-05-2014 11:59

Re: [REQ] Static Enums
 
Quote:

Originally Posted by Black Rose (Post 2120455)
Nope. Make the enum global. You don't have to make the DATA global though. But the difference between global and static is none I believe.

There is a difference between global and static variables: scope. However, apparently, enum's don't seem to work as static.


All times are GMT -4. The time now is 05:57.

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