Raised This Month: $32 Target: $400
 8% 

Can't find the new way to write this Enum


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 12-14-2019 , 15:17   Can't find the new way to write this Enum
Reply With Quote #1

Just trying to get this to compile

PHP Code:
enum Rank
{
    
rankPoints,
    
String:chatRank[64],
    
String:menuRank[64],
    
String:tagRank[64]
}
const 
MAX_RANKS 32;
Rank Ranks[MAX_RANKS][Rank];
int maxRank = -1
Quote:
warning 241: Array-based enum structs will be removed in 1.11. See https://wiki.alliedmods.net/SourcePa...x#Enum_Structs
__________________

Last edited by Elitcky; 12-14-2019 at 16:31.
Elitcky is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 12-15-2019 , 04:55   Re: Can't find the new way to write this Enum
Reply With Quote #2

Since SM 1.10 you should use enum structs. Like this:

Code:
enum struct Rank
{
    int rankPoints;
    char chatRank[64];
    char menuRank[64];
    char tagRank[64];
}
__________________
MAGNAT2645 is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 12-15-2019 , 19:08   Re: Can't find the new way to write this Enum
Reply With Quote #3

Thank u, but now it says this :s

PHP Code:
enum struct Rank
{
    
int rankPoints;
    
char chatRank[64];
    
char menuRank[64];
    
char tagRank[64];
}

const 
MAX_RANKS 32;
Rank Ranks[MAX_RANKS][Rank];
int maxRank = -1

Code:
error 174: symbol 'Rank' is a type and cannot be used as a value
error 101: specify either all dimensions or only the last dimension
error 017: undefined symbol "rankPoints"
error 047: array sizes do not match, or destination array is too small
__________________
Elitcky is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 12-16-2019 , 02:34   Re: Can't find the new way to write this Enum
Reply With Quote #4

"Rank" is a data-type which contains an int, and a char. You can add dimensions to it like any other data-type. (e.g. int foo[32];)

PHP Code:
enum struct Rank
{
    
int rankPoints;
    
char chatRank[64];
}

Rank Ranks[32];

Ranks[0].rankPoints 10;
Ranks[1].rankPoints 20;
Ranks[2].rankPoints 30;
// etc ... 
Kolapsicle is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 12-16-2019 , 11:54   Re: Can't find the new way to write this Enum
Reply With Quote #5

Still can't get it, there is any tutorial or something to understand it better ?

PHP Code:
enum struct Rank
{
    
int rankPoints;
    
char chatRank[64];
    
char menuRank[64];
    
char tagRank[64];
}

Rank Ranks[32]; 
Now it says
Code:
error 017: undefined symbol "rankPoints"
error 017: undefined symbol "chatRank"
error 017: undefined symbol "menuRank"
error 017: undefined symbol "tagRank"
The thing is, than the plugin is trying to use it this ways
PHP Code:
int index;
    do
    {
        
char sec[8];
        
KvGetSectionName(KV2secsizeof(sec));
        
index StringToInt(sec);

        
char chat[64], menu[64], tag[64];
        
Ranks[index][rankPoints] = KvGetNum(KV2"points");

        
KvGetString(KV2"chat"chatsizeof(chat));
        
KvGetString(KV2"menu"menusizeof(menu));
        
KvGetString(KV2"tag"tagsizeof(tag));

        
strcopy(Ranks[index][chatRank], sizeof(chat), chat);
        
strcopy(Ranks[index][menuRank], sizeof(menu), menu);
        
strcopy(Ranks[index][tagRank], sizeof(tag), tag);
    } 
PHP Code:
stock int Function_GetRankNumber(int client)
{
    
int points Function_ReturnPoints(client);
    if(
points <= Ranks[0][rankPoints]) return 0;
    if(
points >= Ranks[maxRank-1][rankPoints]) return maxRank-1;
    for(
int i maxRank-20i--) {
        if(
points >= Ranks[i][rankPoints]) return i;
    }
    return -
1;


So im trying to understand it, but can't get it.
__________________
Elitcky is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-16-2019 , 12:52   Re: Can't find the new way to write this Enum
Reply With Quote #6

Ranks[index][chatRank] becomes Ranks[index].chatRank
etc.
__________________
Ilusion9 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 08:59.


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