SA-MP Forums Archive
strtok vs sscanf - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: strtok vs sscanf (/showthread.php?tid=139000)



strtok vs sscanf - MummyKillerSLO - 03.04.2010

Hello!

I wanna ask, what is better: function strtok or sscanf. I want to ask also what is dcmd .


Re: strtok vs sscanf - Correlli - 03.04.2010

sscanf of course. It's faster and more efficient, and dcmd is a command processor, but I suggest you to use zcmd, it's faster than dcmd.


Re: strtok vs sscanf - MummyKillerSLO - 03.04.2010

ok thanks for the reply


Re: strtok vs sscanf - MenaceX^ - 03.04.2010

sscanf... like da...


Re: strtok vs sscanf - MummyKillerSLO - 03.04.2010

Ermm... One new question: When I make zcmd command, it writes:

Код:
C:\Users\Computer\Desktop\Server\gamemodes\CrazyStunts.pwn(82) : warning 203: symbol is never used: "heal"
The Code:

Код:
command(heal,playerid,params[])
{
	new User;
	if(!sscanf(params,"u",User))
	{
		SetPlayerHealth(User, 100);
	}
	else return SendClientMessage(playerid,0x0000FF,"(USAGE): /Heal (Player ID)");
	return 1;
}



Re: strtok vs sscanf - playdead - 03.04.2010

under OnPlayerCommandText u gotta do:
Код:
dcmd_heal(params[],playerid);
i think it should work


Re: strtok vs sscanf - MummyKillerSLO - 03.04.2010

It wont work because i am using Zcmd not dcmd


Re: strtok vs sscanf - woot - 03.04.2010

pawn Код:
heal(playerid,params[])
{
    new User;
    if(!sscanf(params,"u",User))
    {
        SetPlayerHealth(User, 100);
    }
    else return SendClientMessage(playerid,0x0000FF,"(USAGE): /Heal (Player ID)");
    return 1;
}



Re: strtok vs sscanf - Jay_ - 04.04.2010

Note that strtok isn't that slow. If you prefer it, use it. A lot of people exaggerate theoretical performance without even benchmarking it themselves in the first place.


Re: strtok vs sscanf - [HUN]Gamestar - 04.04.2010

Try this.

pawn Код:
COMMAND:heal(playerid, params[])
{
......
}

pawn Код:
COMMAND:heal(playerid, params[])
{
    new giveplayerid;
   
    if(!sscanf(params,"u",giveplayerid)) {
      SetPlayerHealth(playerid,100.0);
    } else {
      if(IsPlayerConnected(giveplayerid)) {
        SetPlayerHealth(giveplayerid,100.0);
        }
    }
    return 1;
}
And: http://forum.sa-mp.com/index.php?top...6153#msg716153





Re: strtok vs sscanf - Rac3r - 04.04.2010

Quote:
Originally Posted by _Jay_
Note that strtok isn't that slow. If you prefer it, use it. A lot of people exaggerate theoretical performance without even benchmarking it themselves in the first place.
+1

Processing code is super fast, people worrying about a millisecond or two is really silly. We use both, not for any real reason apart from it gets the job done.


Re: strtok vs sscanf - dice7 - 06.04.2010

I actually did some test and found out that sscanf is always faster, but in 'faster' I mean in miliseconds. If a player enters 10 thousand commands at once, sscanf will process them about ~10 miliseconds faster, 100 thousand ~100 milliseconds faster and 1 million commands, sscanf will be about a second faster.

It was tested with a command with only one extra parameter ("/heal 45"), which may made them almost the same speed. But for a player to actually notice the difference, the command would probably have to be something like
"/dosomething [carid] [playerid] [playerid2] [color1] [color2] [color3] [color4] [string1] [string2] [string3] [string4] [something else 1] [something else 2]" and even that would be like half a second in speed.

The final verdict is that use that which is easier for you

Here's the code used for testing
http://pastebin.com/A16tt7CH


Re: strtok vs sscanf - Hiddos - 06.04.2010

Iґm switching over right now.


Re: strtok vs sscanf - aircombat - 06.04.2010

Def. sscanf