Why does this not work ? (Y_INI) -
AIped - 12.11.2013
Alright i am trying to save some values into a file. It worked nice
untill i tried to save a playername (string) into the file.
This is what i got;
pawn Код:
enum cInfo
{
Money,
Sold,
Owner[32],
}
new Companies[MAX_COMPANIES][cInfo];
pawn Код:
SaveCompanyInfo(companyid)
{
new bigstring[50];
format(bigstring, sizeof(bigstring),"/Economy/%s.INI",CompanyNames[companyid]);
new INI:File = INI_Open(bigstring);
INI_SetTag(File, "Company accounts");
INI_WriteInt(File,"Cash",Companies[companyid][Money]);
INI_WriteInt(File,"Status",Companies[companyid][Sold]);
INI_WriteString(File,"Owner",Companies[companyid][Owner]);
INI_Close(File);
}
The parts above actually work fine it just that i cant get the string correctly.
Under here is the part that im dealing with, at the comments you can see that i was trying things out.
pawn Код:
if(!strcmp(cmdtext, "/ownit", true))
{
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name,sizeof(name));
format(string, sizeof(string), "name:%s",name);
// format(string, sizeof(string), "%s", name);
//Companies[0][Owner]= GetPlayerName(playerid, name,sizeof(name));
Companies[0][Owner]= string[32];
SaveCompanyInfo(0);
return 1;
}
If i look into the saved file it shows this;
Cash = 5000
Status = 1
Owner =
After trying different things it sometimes showed up like this;
Cash = 5000
Status = 1
Owner = -
I didnt show the actual 'loading' the file part because thats not what i need to know now.
Re: Why does this not work ? (Y_INI) -
Loot - 12.11.2013
You can't do that.
Companies[0][Owner]= string[32];
Try:
pawn Код:
if(!strcmp(cmdtext, "/ownit", true))
{
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name,sizeof(name));
format(string, sizeof(string), "name:%s",name);
// format(string, sizeof(string), "%s", name);
//Companies[0][Owner]= GetPlayerName(playerid, name,sizeof(name));
Companies[0][Owner]= string;
SaveCompanyInfo(0);
return 1;
}
Re: Why does this not work ? (Y_INI) -
Pottus - 12.11.2013
You can't do this
Companies[0][Owner]= string[32];
It must be this
format(Companies[0][Owner], 32, "%s", string);
Array sizes are not the same.
You can try it here
http://slice-vps.nl:7070/
pawn Код:
#include <a_samp>
enum cInfo
{
Money,
Sold,
Owner[32],
}
new Companies[100][cInfo];
main() {
new name[MAX_PLAYER_NAME+1], string[32]; // switch string size to 24+MAX_PLAYER_NAME+1 (To test)
name = "PlayersName";
format(string, sizeof(string), "name:%s",name);
// format(string, sizeof(string), "%s", name);
//Companies[0][Owner]= GetPlayerName(playerid, name,sizeof(name));
Companies[0][Owner]= string;
printf("%s", Companies[0][Owner]);
return 1;
}
Re: Why does this not work ? (Y_INI) -
AIped - 12.11.2013
That looks very logical but i on both examples i get this error;
error 047: array sizes do not match, or destination array is too small
Note: I had this before i posted, thats why i tried different (messed up) things untill it compiled correct
Re: Why does this not work ? (Y_INI) -
Loot - 12.11.2013
This is beyond 32 chars. (24 * 2 + 1 = 49)
pawn Код:
string[24+MAX_PLAYER_NAME+1]
Change that to:
Re: Why does this not work ? (Y_INI) -
AIped - 12.11.2013
Ah okay it compiles alright but still doesnt save.
this is what i made now;
pawn Код:
if(!strcmp(cmdtext, "/ownit", true))
{
new name[MAX_PLAYER_NAME+1], string[32];
GetPlayerName(playerid, name,sizeof(name));
format(Companies[0][Owner], 32, "%s", string);
Companies[0][Owner]= string;
SaveCompanyInfo(0);
return 1;
}
Re: Why does this not work ? (Y_INI) -
Loot - 12.11.2013
Can you show me the file's input please?
pawn Код:
Company accounts
Score = 30
// etc
Re: Why does this not work ? (Y_INI) -
AIped - 12.11.2013
[Company accounts]
Cash = 5000
Status = 0
Owner =
thats all...it seems the string is empty somehow or not saving that part
Re: Why does this not work ? (Y_INI) -
Loot - 12.11.2013
You messed up the code..
pawn Код:
if(!strcmp(cmdtext, "/ownit", true))
{
new name[MAX_PLAYER_NAME+1], string[32];
GetPlayerName(playerid, name,sizeof(name));
format(Companies[0][Owner], 32, "%s", string); // here -> string is basically null(?)
Companies[0][Owner] = string;
SaveCompanyInfo(0);
return 1;
}
Try:
pawn Код:
if(!strcmp(cmdtext, "/ownit", true))
{
new name[MAX_PLAYER_NAME+1], string[32];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "name:%s", name);
Companies[0][Owner] = string;
SaveCompanyInfo(0);
return 1;
}
Re: Why does this not work ? (Y_INI) -
AIped - 12.11.2013
Yea that was it! thanks man +rep