Raised This Month: $51 Target: $400
 12% 

Colors do not properly show when reading them from a config file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 08-15-2017 , 16:51   Colors do not properly show when reading them from a config file
Reply With Quote #1

Hey, So I've made a config where a operator can change their own colors with \x01...

The problem is whenever I load the data into memory through the KeyValues system, whenever I use it, it actually displays the code rather then converting it to the "color". Would like any help on this problem, thanks

PHP Code:
// Config
"BasePlugins"
{
    
"prefix"            "\x01[\x06SM\x01]"
}

// Code
KeyValues kConfig = new KeyValues("");
kConfig.ImportFromFile(cPath);

kConfig.JumpToKey("BasePlugins");
kConfig.GotoFirstSubKey();

kConfig.GetString("prefix"g_cConfig[CONFIG_PREFIX], 64);
delete kConfig;

// Usage
char cMessage[512];
Format(cMessagesizeof(cMessage), "%s %s%T"g_cConfig[CONFIG_PREFIX], g_cConfig[CONFIG_TEXT], "Reload Config"iClient);
PrintToChat(iClientcMessage); 
Example:

__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 08-15-2017 at 16:53.
OSWO is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-15-2017 , 16:59   Re: Colors do not properly show when reading them from a config file
Reply With Quote #2

\xN is compiler trick. You must set real character in your config.
If you using Microsoft Windows use Alt+N.
Example: to type '\x01' character use Alt+01
For Linux: How to type special characters in Linux?

P.S. I working in Notepad++ and use "Edit->Character Panel".

Last edited by Kailo; 08-15-2017 at 17:06.
Kailo is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 08-15-2017 , 17:02   Re: Colors do not properly show when reading them from a config file
Reply With Quote #3

Quote:
Originally Posted by Kailo View Post
\xN is compiler trick. You must set real char in you config.
If you using Microsof Windows use Alt+N.
Example: to type '\x01' char use Alt+01

P.S. I working in Notepad++ and use "Edit->Character Panel".
Ahh, That explains the weird SOH things I would always see in Source Language files, Thanks

Here's a useful package for anyone using Atom: https://atom.io/packages/unicode-input
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 08-15-2017 at 17:12.
OSWO is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 08-15-2017 , 18:26   Re: Colors do not properly show when reading them from a config file
Reply With Quote #4

Could also use other strings like {green} and replace in code with the actual character before using it.
hmmmmm is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 08-15-2017 , 20:32   Re: Colors do not properly show when reading them from a config file
Reply With Quote #5

A side note:
Code:
PrintToChat(iClient, cMessage);
>>
Code:
PrintToChat(iClient, "%s", cMessage);
__________________
retired
shavit is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-16-2017 , 05:12   Re: Colors do not properly show when reading them from a config file
Reply With Quote #6

Try kConfig.SetEscapeSequences(true) before importing the file.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-16-2017 , 08:59   Re: Colors do not properly show when reading them from a config file
Reply With Quote #7

Quote:
Originally Posted by DJ Tsunami View Post
Try kConfig.SetEscapeSequences(true) before importing the file.
The KV escape sequence support doesn't include arbitrary characters.

https://mxr.alliedmods.net/hl2sdk-sd...lbuffer.cpp#59
__________________

Last edited by asherkin; 08-16-2017 at 08:59.
asherkin is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-16-2017 , 09:01   Re: Colors do not properly show when reading them from a config file
Reply With Quote #8

Quote:
Originally Posted by DJ Tsunami View Post
Try kConfig.SetEscapeSequences(true) before importing the file.
Don't think this helps. After a quick look, I think it only handles these: https://github.com/alliedmodders/hl2...er.cpp#L59-L71
Fyren is offline
Reply



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 23:41.


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