Raised This Month: $ Target: $400
 0% 

diff


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 01-23-2020 , 05:09   diff
Reply With Quote #1

any difference b/w

PHP Code:
enum Data
{
    
Data1,
    
Date2


PHP Code:
enum _:Data
{
    
Data1,
    
Date2

Also if i want to store string is this correct?


PHP Code:
enum _:Data
{
    const 
Data1[10]="This is test string",
    
Date2

__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2020 , 07:57   Re: diff
Reply With Quote #2

Using _: will make the compiler not give you warnings for not correctly tagging variables with the enum name or assigning values to the array that are not defined in the enum.

For this purpose, the enum is just a mechanism for sizing the array, not for storing data.
PHP Code:
enum _:Test
{
    
Data110 ],
    
Data2
}

new 
TestDataTest ]; 
__________________

Last edited by Bugsy; 01-23-2020 at 07:58.
Bugsy is offline
Old 01-23-2020, 08:09
Sanjay Singh
This message has been deleted by Sanjay Singh.
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 01-23-2020 , 09:06   Re: diff
Reply With Quote #3

is this correct way?

PHP Code:
enum _:Data
{
    const 
Data1[32]="This is test string",
    
Date2

__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 01-23-2020 , 10:16   Re: diff
Reply With Quote #4

Did you compile that code?
redivcram is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-23-2020 , 11:28   Re: diff
Reply With Quote #5

A note on tags: there are 2 types of tags: weak and strong tags. A strong tag begins with a capital letter, a weak tag with a lowercase letter.

Consider the following code:
PHP Code:
#include <amxmodx>

enum States
{
    
STATE_000,
    
STATE_001
    
//..other states
}

getInitialState()
{
    return 
STATE_000;
}

public 
plugin_init()
{
    
server_print("Initial state is %d"getInitialState());

The tag "States" starts with a capital letter, therefore it is a strong tag. When we try to return STATE_000 from getInitialState we will get a tag mistmatch because the function is not tagged as "States".

Now consider this code:
PHP Code:
#include <amxmodx>

enum states
{
    
STATE_000,
    
STATE_001
    
//..other states
}

getInitialState()
{
    return 
STATE_000;
}

public 
plugin_init()
{
    
server_print("Initial state is %d"getInitialState());

It is the same code, but we changed the tag name from "States" to "states". Now we will not get a tag mismatch, because the tag is weak.
__________________

Last edited by HamletEagle; 01-23-2020 at 11:29.
HamletEagle is offline
thEsp
BANNED
Join Date: Aug 2017
Old 01-23-2020 , 12:30   Re: diff
Reply With Quote #6

Quote:
Originally Posted by Sanjay Singh View Post
is this correct way?

PHP Code:
enum _:Data
{
    const 
Data1[32]="This is test string",
    
Date2

No. You are trying to create a static constant variable in an enumeration, which obviously won't work. Try creating an enumeration and then creating a global sample.
Check this tutorial for more: https://forums.alliedmods.net/showthread.php?t=26634.
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2020 , 18:21   Re: diff
Reply With Quote #7

PHP Code:
enum Test
{
    
Data132 ],
    
Data2
}

new 
TestDataTest ];
    
copyTestDataData1 ] , charsmaxTestDataData1 ] ) , "Test string" );
TestDataData2 ] = 4213
__________________

Last edited by Bugsy; 01-23-2020 at 18:22.
Bugsy is offline
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 01-24-2020 , 03:07   Re: diff
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
PHP Code:
enum Test
{
    
Data132 ],
    
Data2
}

new 
TestDataTest ];
    
copyTestDataData1 ] , charsmaxTestDataData1 ] ) , "Test string" );
TestDataData2 ] = 4213
So i can use copy out of function or in plugin_init?
__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-24-2020 , 03:26   Re: diff
Reply With Quote #9

You do it in a function(where it is needed). plugin_init is also a function.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 02:45.


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