Cannot get a string from a file [+REP]
#1

expression has no effect | line LoadClanData(); (in the public OnGameModeInit)

PHP код:
#define MAX_CLANS 50
enum ClanInfo
{
    
Test[64]
}
new 
ClanDB[MAX_CLANS][ClanInfo];
#define LoadClanData INI_ParseFile(clanFile(), "LoadClan", .bExtra = true);
public OnGameModeInit()
{
    
LoadClanData();
    return 
1;
}
function 
LoadClan(name[], value[])
{
    for(new 
0MAX_CLANSi++){
    
INI_String("Test",ClanDB[i][Test],64);}
    return 
1;
}
stock SaveClanFile()
{
    for(new 
0MAX_CLANSi++){
    new 
INI:cf INI_Open(clanFile());
    
INI_SetTag(cf"Database");
    
INI_WriteString(cf,"Test",ClanDB[MAX_CLANS][Test]);
    
INI_Close(cf);}
}
stock clanFile()
{
    new 
String[64];
    for(new 
0MAX_CLANSi++){
    
format(String,sizeof(String),"Clans/%s.ini",i);}
    return 
String;
}
CMD:test(playerid,params[]){
LoggedCMD OwnerCMD
new String[128];
for(new 
0MAX_CLANSi++){
format(String,sizeof(String),"%s",ClanDB[i][Test]);
MSG(playerid,-1,String);}
return 
1;} 
Reply
#2

Consider using SQLite or MySQL, I don't think creating a clan system using INI is a good idea at all. If you cba learning SQL, you can simply use this include or this which is similar to Y_INI syntax but for MySQL and SQLite, it's much better performance plus easy to find errors.
Reply
#3

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
Consider using SQLite or MySQL, I don't think creating a clan system using INI is a good idea at all. If you cba learning SQL, you can simply use this include or this which is similar to Y_INI syntax but for MySQL and SQLite, it's much better performance plus easy to find errors.
well i'm not really into learning a new library I just wanna know how to fix this issue :[
Reply
#4

Quote:
Originally Posted by Lirbo
Посмотреть сообщение
I tried to get a string from a file of a clan but when i try to use /test it shows nothing

PHP код:
#define MAX_CLANS 50
enum ClanInfo
{
    
Test[64]
}
new 
ClanDB[MAX_CLANS][ClanInfo];
#define LoadClanData INI_ParseFile(clanFile(playerid), "LoadClan", .bExtra = true, .extra = playerid);
function LoadClan(playeridname[], value[])
{
    for(new 
0MAX_CLANSi++){
    
INI_String("Test",ClanDB[i][Test],64);}
    return 
1;
}
stock SaveClanFile(playerid)
{
    for(new 
0MAX_CLANSi++){
    new 
INI:cf INI_Open(clanFile(playerid));
    
INI_SetTag(cf"Database");
    
INI_WriteString(cf,"Test",ClanDB[MAX_CLANS][Test]);
    
INI_Close(cf);}
}
stock clanFile(playerid)
{
    new 
String[64];
    
format(String,sizeof(String),"Clans/%s.ini",DB[playerid][Clan]);
    return 
String;
}
CMD:test(playerid,params[]){
LoggedCMD OwnerCMD
new String[128], clanid DB[playerid][Clan];
format(String,sizeof(String),"%s",ClanDB[clanid][Test]);
MSG(playerid,-1,String);
return 
1;} 
Rewrite your whole code:
There is no intendation.
Your LoadClanData is completly wrong.
Your LoadClan is wrong too.
DB[playerid][Clan] is an intenger and a string as the same time in your script.
Your whole code is horrible to read.

NB: Don't use stock.
Reply
#5

If you are just starting with YINI, you could use dini2 instead which is faster and easiest.
Reply
#6

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Rewrite your whole code:
There is no intendation.
Your LoadClanData is completly wrong.
Your LoadClan is wrong too.
DB[playerid][Clan] is an intenger and a string as the same time in your script.
Your whole code is horrible to read.

NB: Don't use stock.
I fixed most of the issues, please check again the code up there I edited it.

and yea,
I'm aware to the fact my code is horrible to read but I got used to it and I hate making it normal it takes a lot of space. I like it all tiny.
Reply
#7

Quote:
Originally Posted by Lirbo
Посмотреть сообщение
I fixed most of the issues, please check again the code up there I edited it.

and yea,
I'm aware to the fact my code is horrible to read but I got used to it and I hate making it normal it takes a lot of space. I like it all tiny.
Expression has no effect because you defined a macro but this not a macro there, this is a function.
Anyway you hate, you have to do it when you are newbie, nothing pejorative.
I rewrote your code BUT you need to add code which create your file before load it.
PHP код:
#define MAX_CLANS 50 
enum ClanInfo 

    
Test[64

new 
ClanDB[MAX_CLANS][ClanInfo]; 
public 
OnGameModeInit() 

    
LoadClanData(); 
    return 
1

forward LoadClan_data(clanidname[],value[]);
public 
LoadClan_data(clanidname[],value[])
{
    
INI_String("Test",ClanDB[clanid][Test],64);
    return 
1;
}
SaveClanFile() 

    for(new 
0MAX_CLANSi++)
    { 
        new 
INI:cf INI_Open(clanFile(i)); 
        
INI_SetTag(cf"Database"); 
        
INI_WriteString(cf,"Test",ClanDB[i][Test]); 
        
INI_Close(cf);
    } 

clanFile(const clanid

    static 
String[64]; 
    
format(String,sizeof(String),"Clans/%s.ini",clanid);
    return 
String

LoadClanData()
{
    for(new 
ii<MAX_CLANSi++)
    {
        if(!
fexist(clanFile(i))) continue;
        
INI_ParseFile(clanFile(i), "LoadClan_data", .bExtra true); 
        
//INI_ParseFile(clanFile(i), "LoadClan_data", .bExtra = true, .extra = i); -> Only if the line above doesn't work.
    
}
}
/*
CMD:test(playerid,params[]){ 
LoggedCMD OwnerCMD 
new String[128]; 
for(new i = 0; i < MAX_CLANS; i++){ 
format(String,sizeof(String),"%s",ClanDB[i][Test]); 
MSG(playerid,-1,String);} 
return 1;}  */
CMD:test(playerid)
{
    for(new 
ii<MAX_CLANSi++)
    {
        
format(String,sizeof(String),"%s",ClanDB[i][Test]); 
        
MSG(playerid,-1,String);
    }
    return 
1;

And, please, check some tutos about YINI.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)