Problem with a string value.
#1

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.
Reply
#2

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...
Reply
#3

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;
}
Reply
#4

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
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)