AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Line break isn't working in convar. (https://forums.alliedmods.net/showthread.php?t=305192)

Visual77 02-10-2018 12:41

Line break isn't working in convar.
 
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);
}


Visual77 02-10-2018 13:22

Re: Line break isn't working in convar.
 
Omg, fixed it.
Code:

ReplaceString(buffer, sizeof(buffer), "\\n", "\n");

WildCard65 02-10-2018 21:27

Re: Line break isn't working in convar.
 
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.


All times are GMT -4. The time now is 10:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.