SA-MP Forums Archive
strval - 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: strval (/showthread.php?tid=357410)



strval - SnG.Scot_MisCuDI - 07.07.2012

Okay, so im making a /countdown command, and im probably making it harder than it really should be. But im trying to convert the integer into a string or vise versa so i can use TextDrawSetString. But even when i strval i get an error on the TextDrawSetString line.

pawn Код:
CMD:countdown(playerid,params[])
{
    new string[4] = "4";
    new countdown = strval(string);
   
    CountTime = countdown;
       
    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);
    if(sscanf(params, "i", countdown)) return Usage(playerid, "/countdown [time]");

    TextDrawSetString(AnnText, CountTime);
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);
    return 1;
}
i dont know how to use strval so its probably wrong... I just want the textdrawsetstring to be the number you type in for countdown..


Re: strval - Finn - 07.07.2012

Try valstr. https://sampwiki.blast.hk/wiki/Valstr


Re: strval - [MM]RoXoR[FS] - 07.07.2012

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
Okay, so im making a /countdown command, and im probably making it harder than it really should be. But im trying to convert the integer into a string or vise versa so i can use TextDrawSetString. But even when i strval i get an error on the TextDrawSetString line.

pawn Код:
CMD:countdown(playerid,params[])
{
    new string[4] = "4";
    new countdown = strval(string);
   
    CountTime = countdown;
       
    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);
    if(sscanf(params, "i", countdown)) return Usage(playerid, "/countdown [time]");

    TextDrawSetString(AnnText, CountTime);
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);
    return 1;
}
i dont know how to use strval so its probably wrong... I just want the textdrawsetstring to be the number you type in for countdown..
y are you using string?

Use this instead
pawn Код:
CMD:countdown(playerid,params[])
{
    new string[4];
    new countdown = 4;

    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);
    if(sscanf(params, "i", countdown)) return Usage(playerid, "/countdown [time]");

    format(string,sizeof(string),"%d",countdown);
    TextDrawSetString(AnnText, string);
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);
    return 1;
}



Re: strval - SnG.Scot_MisCuDI - 07.07.2012

i dont want the ocuntdown to equal 4. I want the countdown to equal the number typed in by the player

Quote:
Originally Posted by Finn
Посмотреть сообщение
i dont understand how to use it.. thats the problem here


Re: strval - ReneG - 07.07.2012

pawn Код:
CMD:countdown(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);

    new
        digit = strval(params); // here we make what the player typed into an
                                // integer using strval

    // isnull() checks if params is empty
    // !strval(params) checks if it wasn't a number or they typed 0
    if(isnull(params) || !strval(params))
    {
        return SendClientMessage(playerid, -1, "USAGE: /countdown [seconds]");
    }
   
    // valstr(digit) turns the variable digit
    // into a string and returns it.
    TextDrawSetString(AnnText, valstr(digit));
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);
   
    return 1;
}
So simple, you don't need sscanf.


Re: strval - SnG.Scot_MisCuDI - 07.07.2012

pawn Код:
(3692) : error 035: argument type mismatch (argument 1)
(3682) : warning 204: symbol is assigned a value that is never used: "digit"
3692
pawn Код:
TextDrawSetString(AnnText, valstr(digit));



Re: strval - ReneG - 07.07.2012

Ah, you need to store the result in a string.


pawn Код:
CMD:countdown(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);

    new
        digit = strval(params), // we can make more than one variable
        seconds[8];             // by using a comma

    if(isnull(params) || !digit)
    {
        return SendClientMessage(playerid, -1, "USAGE: /countdown [seconds]");
    }
    // this is the correct way to use valstr
    // we store the amount of 'digits' into
    // the string 'seconds'
    valstr(seconds, digit);
   
    TextDrawSetString(AnnText, seconds); // we then set the string of the textdraw to 'seconds'
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);

    return 1;
}
EDIT:

You can even do this without making a new string.

pawn Код:
CMD:countdown(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return ErrorMsg(playerid);

    new
        digit = strval(params);

    if(isnull(params) || !digit)
    {
        return SendClientMessage(playerid, -1, "USAGE: /countdown [seconds]");
    }

    valstr(params, digit);
   
    TextDrawSetString(AnnText, params);
    TextDrawShowForAll(AnnText);
    CountTimer = SetTimer("CountDown",1000,true);

    return 1;
}