strtok vs sscanf
#1

Hello!

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

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

ok thanks for the reply
Reply
#4

sscanf... like da...
Reply
#5

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

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

It wont work because i am using Zcmd not dcmd
Reply
#8

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

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

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


Reply
#11

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

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

Iґm switching over right now.
Reply
#14

Def. sscanf
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)