SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 20/01/2020, 05:18 PM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 311
Reputation: 8
Default Enum string return just first letter

pawn Code:
enum UserInfoEnum
{
    Name[24],
    RankName[24]
};
new UserInfo[MAX_PLAYERS][UserInfoEnum];
When i want return the word stored on enum string, just return first letter.
for example:
pawn Code:
public OnPlayerConnect(playerid)
{
    new string[46];
    UserInfo[playerid][Name] = "Test";
    format(string, sizeof string, "Your name is: %s", UserInfo[playerid][Name]);
    SendClientMessage(playerid, -1, string);
    //[out put] Your name is: T
    return 1
}

How to fix it?
Vizi10 is offline   Reply With Quote
Old 20/01/2020, 06:02 PM   #2
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 820
Reputation: 68
Default Re: Enum string return just first letter

Because you're saving [Name] just like you would save an integer and it's not correct.

The correct way to parse a string is using strcpy:

pawn Code:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

Then in your command:

pawn Code:
strcpy(UserInfo[playerid][Name], "Test", 5);

Where 5 is the lenght of the string.

Since seems you're saving the player name, i'd suggest you to use MAX_PLAYER_NAME lenght. (Which is the same as 24 but i do prefer the first one).
Symon 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
Get Last Letter or number in string Banditukas Scripting Help 6 06/12/2014 03:04 PM
String misses a letter thimo Scripting Help 9 08/01/2012 06:20 PM
Only first letter, instead of the whole word HELP please [enum + mySQL + Variables] jesse237 Scripting Help 1 22/10/2011 12:05 PM
Letter in string. Dreftas Help Archive 2 06/10/2009 09:10 PM
String only shows first-letter. shitbird Help Archive 4 20/09/2009 02:49 PM


All times are GMT. The time now is 02:29 PM.


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