AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   diff (https://forums.alliedmods.net/showthread.php?t=321062)

Sanjay Singh 01-23-2020 05:09

diff
 
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



Bugsy 01-23-2020 07:57

Re: diff
 
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 ]; 


Sanjay Singh 01-23-2020 09:06

Re: diff
 
is this correct way?

PHP Code:

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



redivcram 01-23-2020 10:16

Re: diff
 
Did you compile that code?

HamletEagle 01-23-2020 11:28

Re: diff
 
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.

thEsp 01-23-2020 12:30

Re: diff
 
Quote:

Originally Posted by Sanjay Singh (Post 2681342)
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.

Bugsy 01-23-2020 18:21

Re: diff
 
PHP Code:

enum Test
{
    
Data132 ],
    
Data2
}

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


Sanjay Singh 01-24-2020 03:07

Re: diff
 
Quote:

Originally Posted by Bugsy (Post 2681391)
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?

HamletEagle 01-24-2020 03:26

Re: diff
 
You do it in a function(where it is needed). plugin_init is also a function.


All times are GMT -4. The time now is 02:45.

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