Loop an enum
#1

Hey.
I'm trying to loop through an enum. The problem is, I can't do it correctly because I've a string + integer.
My enum:
PHP код:
enum E_FACTION_INFOS
{
    
fSQLID,
    
fName[MAX_FAC_RANK_NAME],
    
fDiminutive[MAX_DIMINUTIVE_LT],
    
fType,
    
fNumberOfRank,
    
fMaxMembers,
    
fPay,
    
fBank,
    
fState,...
};
new 
f_Info[MAX_ALL_FACT][E_FACTION_INFOS];
    for(new 
1E_FACTION_INFOS:fNamemax_fields_per_table[STATS_INFOS]; i++, k++)
    {
        
mysql_format(dbsec_querysizeof(sec_query), ", `%s` = '%s'"SQL_Fields[0][i][sqlName], SQL_Fields[0][i][sqlSpecifier]);
        
printf("[debug-A] %s"sec_query);
        
mysql_format(dbsec_querysizeof(sec_query), sec_queryf_Info[factionid][k]);
        
printf("[debug-B] %s\n"sec_query);
        
strcat(querysec_query);
    } 
It simply print as : f_Info[factionid][fName][0], f_Info[factionid][fName][1], ... instead of f_Info[factionid][fName], f_Info[factionid][fDiminutive].
NB: The loop works correctly apart from the string values

Second question: 4D arrays cost a lot of memory or there any changes?

Edit: I can't use an another dimensions in the loop.
Reply
#2

Simply do:
pawn Код:
E_FACTION_INFOS:k
Reply
#3

Quote:
Originally Posted by CheezIt
Посмотреть сообщение
Simply do:
pawn Код:
E_FACTION_INFOS:k
Did you even read the code entierly ... ?
Reply
#4

incrementing string is out of logic (k++).That will print characters from beginning.For eg (Samp ,amp,mp,p)
If that's not what you getting then provide a proper test code to reproduce the same problem for analysing.
Reply
#5

Quote:
Originally Posted by SyS
Посмотреть сообщение
incrementing string is out of logic (k++).That will print characters from beginning.For eg (Samp ,amp,mp,p)
If that's not what you getting then provide a proper test code to reproduce the same problem for analysing.
Quote:
Originally Posted by Dayrion
Посмотреть сообщение
It simply print as : f_Info[factionid][fName][0], f_Info[factionid][fName][1], ... instead of f_Info[factionid][fName], f_Info[factionid][fDiminutive].
NB: The loop works correctly apart from the string values
^ That should answer you.
Reply
#6

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
^ That should answer you.
Huh? How could that answer him? Read what he posted carefully.You are incrementing string which will set the pointer from begginning to each character.Also provide proper test code as SyS said to reproduce the problem and analyse as your script is known only to you others even don't saw it before and also you are not clear enough in explaining the actual problem.
Reply
#7

Quote:
Originally Posted by GhostHacker9
Посмотреть сообщение
Huh? How could that answer him? Read what he posted carefully.You are incrementing string which will set the pointer from begginning to each character.Also provide proper test code as SyS said to reproduce the problem and analyse as your script is known only to you others even don't saw it before and also you are not clear enough in explaining the actual problem.
Alright. So I don't understand what he meant.
Quote:
Originally Posted by SyS
Посмотреть сообщение
incrementing string is out of logic (k++)
It's not for the string but it's for the enum.
Quote:
Originally Posted by SyS
Посмотреть сообщение
If that's not what you getting then provide a proper test code to reproduce the same problem for analysing.
I already did that before posting there.
Actually I'm looping from fType (3) to fState(8 ). It works perfectly. The "k" is incrementing my enum!
If I'm starting from fName(1), "k" will increment the string and not the enum.
So I'm looking for a solution because I want "k" incrementing the enum. E_FACTION_INFOS tag on "k" change nothing.
I hope this more clear. Apologize if is it not. My english is pretty bad.
Reply
#8

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Did you even read the code entierly ... ?
Or maybe you're just ignorant?

This: E_FACTION_INFOS:k = fName - is garbage, simply set k to an integer value where you want it to start looping at

You'll then do:
f_Info[factionid][E_FACTION_INFOS:k]
Reply
#9

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Alright. So I don't understand what he meant.

It's not for the string but it's for the enum.

I already did that before posting there.
Actually I'm looping from fType (3) to fState(8 ). It works perfectly. The "k" is incrementing my enum!
If I'm starting from fName(1), "k" will increment the string and not the enum.
So I'm looking for a solution because I want "k" incrementing the enum. E_FACTION_INFOS tag on "k" change nothing.
I hope this more clear. Apologize if is it not. My english is pretty bad.
you are assigning k to a string value that will create corrupted memory as you incrementing it. What you now doing is looping through that string's memory location. The solution above posted is the correct way to do it.
Reply
#10

Yes instead of that use this (provided from above test code posted)
PHP код:
#include <a_samp>
enum ENUMERATOR
{
    
value,
    
string[24]
}
new ARRAY[][
ENUMERATOR]={
{
1,"Ghost"},
{
2,"dariyon"},
{
3,"kalcor"}
}

main()
{
 
    for(new 
03;++i)
    {
        
printf("string %s \n", ARRAY[i][ENUMERATOR:1]);
        
printf("digit %d \n ",ARRAY[i][ENUMERATOR:0]);
    }

Prints

Код:
string Ghost
digit 1 
string dariyon
digit 2
string kalcor
digit 3
Hope that was clear to you @op
Also order is an important thing here.As the data type is to be known (array or plane).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)