value assignment
#1

Hi , once read the below codes.

Код:
new time[MAX_PLAYERS];
CMD:timeshow(playerid,params[])
{
    new time_seconds;
    if(sscanf(params,"d",time)) return SendClientMessage(playerid,-1,"/show <seconds>");
    time[playerid] = time //what he entered in the params.
return 1;

}
How can i assign value to time[playerid] of what was entered in the params? that means /timeshow 100. then the value of time[playerid] must be 100.
Reply
#2

Try intializing the value before? If you want to. Or you only want the value of second?
Reply
#3

No I want wat ever he type must be assigned in time[playerid] anyone?
Reply
#4

pawn Код:
new time_seconds;
if(sscanf(params,"d",time_seconds)) return SendClientMessage(playerid,-1,"/show <seconds>");
time[playerid] = time_seconds; //what he entered in the params.
?? you need check value if is not < 0
Reply
#5

i did everything like what you said it was writing mistake in the main post.
Код:
new time_seconds;
if(sscanf(params,"d",time_seconds)) return SendClientMessage(playerid,-1,"/show <seconds>");
time[playerid] = time_seconds; //what he entered in the params.
time[playerid] doesn't get the value still.
Reply
#6

DEBUG:
pawn Код:
new time[MAX_PLAYERS];
CMD:timeshow(playerid,params[])
{
    printf("Before: %i, Parameters: %s", time[playerid], params);
   
    if(sscanf(params, "d", time[playerid]))
        return SendClientMessage(playerid, -1, "/show <seconds>");
       
    printf("After: %i, What it should be: %s", time[playerid], strval(params));
    return 1;
}
Execute the command at least three times, and check your console. Show us the results if you're willing to.


Also, next time you post in the Scripting Help section please provide more details... Like at least tell us what command processor you're using, many of them use the syntax you provided. Or even better show us other things you tried, like if you debugged it at all or immediately came here instead of TRYING to debug, for all we know you've already tried what I just gave you. Those are just two examples of what you could've done.
Furthermore you should've gave this thread a proper title, perhaps "Assigning variable failing with sscanf." Then people who don't know jack shit about sscanf or assigning variables are less likely to come. Yours definitely wasn't the worst title I've seen, just trying to improve this section.
Not sure why I'm typing all of this... I'm just tired... Going to sleep now...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)