SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 01/07/2014, 09:20 AM   #1
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Strmid - Incorrect Usage?

I changed:

pawn Code:
format(PlayerInformation[playerid][String], 64, "N/A");

to:

pawn Code:
strmid(PlayerInformation[playerid][String], "N/A", 0, 64);

And it doesn't seem to have an effect -- does strmid only work when copying strings?
DrakeX is offline   Reply With Quote
Old 01/07/2014, 10:15 AM   #2
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,103
Reputation: 523
Default Re: Strmid - Incorrect Usage?

http://wiki.sa-mp.com/wiki/Strmid
__________________

Kar's Cops and Robbers 2019
Threshold is offline   Reply With Quote
Old 01/07/2014, 11:38 AM   #3
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Re: Strmid - Incorrect Usage?

Real helpful...

Anyways, for anyone wondering how I managed to fix this, I changed:

pawn Code:
strmid(PlayerInformation[playerid][String], "N/A", 0, 64);

to:

pawn Code:
strmid(PlayerInformation[playerid][String], "N/A", 0, strlen("N/A"), 64);
DrakeX is offline   Reply With Quote
Old 01/07/2014, 11:47 AM   #4
sammp
Gangsta
 
sammp's Avatar
 
Join Date: Jan 2014
Posts: 585
Reputation: 49
Default Re: Strmid - Incorrect Usage?

That method is very inefficient if I'm writing a long message, as the line is going to be huge.


An easier method can be this:
pawn Code:
new string[128];
strmid(string, "N/A", 0, sizeof(string), 128);

Correct me if im wrong.
__________________
SA-MP must become open-source to maximise longetivity of the project.
sammp is offline   Reply With Quote
Old 01/07/2014, 11:49 AM   #5
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,197
Reputation: 98
Default Re: Strmid - Incorrect Usage?

Why would you want to use strmid anyway?
pawn Code:
format(PlayerInformation[playerid][String], 64, "N/A");

Is a lot easier in your case.

If you wanted to use strmid, it would need to be this:
pawn Code:
new string[126];
format(string, 126, "N/A");
strmid(PlayerInformation[playerid][String], string, 0, strlen(string), 126);

I'm sure you can tell the difference between the two - using strmid brings in unneeded lines and usage. Normally you would use strmid for something like this:
pawn Code:
new string[126];
format(string, 126, "%s", GetPlayersName(playerid));
strmid(PlayerInformation[playerid][Name], string, 0, strlen(string), 126);

Even then, you can use format, which in my opinion is a lot easier, because it would turn into:
pawn Code:
format(PlayerInformation[playerid][Name], 126, "%s", GetPlayersName(playerid));
__________________
lol
Jack_Leslie is offline   Reply With Quote
Old 01/07/2014, 01:33 PM   #6
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,103
Reputation: 523
Default Re: Strmid - Incorrect Usage?

Quote:
Originally Posted by DrakeX View Post
Real helpful...
You asked:
"does strmid only work when copying strings?"

I gave you a page that explains EXACTLY what strmid is used for, and why you SHOULDN'T be using it for this situation.
__________________

Kar's Cops and Robbers 2019
Threshold is offline   Reply With Quote
Old 01/07/2014, 01:38 PM   #7
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: Strmid - Incorrect Usage?

Quote:
Originally Posted by Jack_Leslie View Post
Why would you want to use strmid anyway?
pawn Code:
format(PlayerInformation[playerid][String], 64, "N/A");

Is a lot easier in your case.

If you wanted to use strmid, it would need to be this:
pawn Code:
new string[126];
format(string, 126, "N/A");
strmid(PlayerInformation[playerid][String], string, 0, strlen(string), 126);

I'm sure you can tell the difference between the two - using strmid brings in unneeded lines and usage. Normally you would use strmid for something like this:
pawn Code:
new string[126];
format(string, 126, "%s", GetPlayersName(playerid));
strmid(PlayerInformation[playerid][Name], string, 0, strlen(string), 126);

Even then, you can use format, which in my opinion is a lot easier, because it would turn into:
pawn Code:
format(PlayerInformation[playerid][Name], 126, "%s", GetPlayersName(playerid));
Don't! Format is slower - in fact, the best way to copy a string to another is memcpy or strcat (http://forum.sa-mp.com/showthread.php?t=309130).
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] SA:MP Images usage, list and usage. Partner Tutorials 23 26/03/2016 11:00 PM
GetDynamicObjectPos & Rot incorrect? Phil_Cutcliffe Scripting Help 2 23/02/2014 01:23 PM
Incorrect collisions leong124 Bug Reports 6 29/09/2011 12:19 PM
Incorrect Version? Arct Client Support 0 11/01/2011 11:59 AM
Incorrect string from AMX izstas Plugin Development 1 09/01/2010 09:57 PM


All times are GMT. The time now is 10:17 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.