Raised This Month: $95 Target: $400
 23% 

Solved Line break isn't working in convar.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Visual77
Veteran Member
Join Date: Jan 2009
Old 02-10-2018 , 13:41   Line break isn't working in convar.
Reply With Quote #1

I was certain I had asked this before but I couldn't find it from search.

How do you read a (line break) \n in a convar?

The line break is not treated as a line break when the message is printed to the client.

Code:
Server.cfg -> convar_message "Hi. \nThis is my line break."

ConVar hintMsg;

public void OnPluginStart()
{
	hintMsg = CreateConVar("convar_message", "", "Hint message");
}

void PrintMessage(int client)
{
	char buffer[256];
        hintMsg.GetString(buffer, sizeof(buffer));
	if (!strlen(buffer)) return;
	PrintHintText(client, buffer);
}

Last edited by Visual77; 02-10-2018 at 14:22.
Visual77 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 02-10-2018 , 14:22   Re: Line break isn't working in convar.
Reply With Quote #2

Omg, fixed it.
Code:
ReplaceString(buffer, sizeof(buffer), "\\n", "\n");
Visual77 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-10-2018 , 22:27   Re: Line break isn't working in convar.
Reply With Quote #3

Leaving this here for future people:
The problem was that C++ was applying an automatic escape delimiter to special characters: (ex: <back-slash>, <double quote>) before handing the string off to the calling code.

Example:
Text file: Hello user, "ALPHA", please provide input: \ERROR
Calling code receives: "Hello user, \"ALPHA\", please provide input: \\ERROR"

Note: Manually writing in escape sequences (ex: '\t', '\n') in a file is treated as 2 characters instead of a single character, this trips the automatic escape feature on the backslash.
__________________
WildCard65 is offline
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

Forum Jump


All times are GMT -4. The time now is 01:11.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode