SA-MP Forums Archive
Problem with a string value. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with a string value. (/showthread.php?tid=363036)



Problem with a string value. - Emre__ - 26.07.2012

pawn Код:
new CRaceName[128];

COMMAND:loadrace(playerid, params[])
{
    new file_name[128], str[256];
    if(RaceAdmin == 1 && GetPVarInt(playerid, "admin_level") < 2)
        return SendClientMessage(playerid, red, "Error: You are not authorized to use this command.");
    Racemode = 0; Racelaps = 1;
    if(sscanf(params, "s[128]", file_name))
        return SendClientMessage(playerid, yaris, "Usage: /loadrace [race name]");
    if(LoadRace(file_name) == 0)
        return SendClientMessage(playerid, red ,"- Race - Race file couldn't find.");
   
    LoadRace(file_name);
    format(CRaceName, sizeof(CRaceName), "%s", file_name);
    format(str, sizeof(str), "- Race - Race %s is loaded.", CRaceName);
    SendClientMessage(playerid, yaris, str);
}
The problem is when I echo out CRaceName value, it shows nothing. But file_name value works properly. Please help me.


Re: Problem with a string value. - Babul - 26.07.2012

can i see the LoadRace() callback please? i think the file_name gets screwed in that callback maybe. i also wonder why you LoadRace() twice...


Re: Problem with a string value. - Emre__ - 26.07.2012

Here it is.
pawn Код:
public LoadRace(tmp[])
{
    new i;
    format(raceName, sizeof(raceName), "%s.yr", tmp);
   
    LCurrentCheckpoint = -1;

    new File:raceFile = fopen(raceName, io_read);
    fread(raceFile, tmp, 64);
   
    i = 0;
    while(fread(raceFile, tmp, 64, false))
    {
        LCurrentCheckpoint++;
        i = 0;

        RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(tmp, i));
        RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(tmp, i));
        RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(tmp, i));
    }
    fclose(raceFile);
    return 1;
}



Fixxx - arman'as - 26.07.2012

Quote:

COMMAND:loadrace(playerid, params[])
{
new file_name[128], str[256];
if(RaceAdmin == 1 && GetPVarInt(playerid, "admin_level") < 2)
return SendClientMessage(playerid, red, "Error: You are not authorized to use this command.");
Racemode = 0; Racelaps = 1;
if(sscanf(params, "s[128]", file_name))
return SendClientMessage(playerid, yaris, "Usage: /loadrace [race name]");
if(LoadRace(file_name) == 0)
return SendClientMessage(playerid, red ,"- Race - Race file couldn't find.");

format(CRaceName, sizeof(CRaceName), "%s", file_name);
format(str, sizeof(str), "- Race - Race %s is loaded.", CRaceName);
SendClientMessage(playerid, yaris, str);
LoadRace(file_name);
}

I think that


Re: Fixxx - Emre__ - 26.07.2012

Problem is solved with sscanf
Under public LoadRace(tmp[]):
pawn Код:
sscanf(tmp, "s", CRaceName);