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

Solved Translation and string bugs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 04-20-2018 , 14:00   Translation and string bugs
Reply With Quote #1

I'm using SmartMenu (methodmap from Menu) that have AddItemFormat method (very useful) and SmartPanel (methodmap from Panel).
My problem is that menu/panel can't translate phrase via client index (just throw error like "Translation failed: invalid client index 1431192909").

This problem seems to appear only on SmartMenu and SmartPanel methods that use VFormat.
Example:
Code:
public Action CMD_Test(int client, int args) {
	SmartPanel hPanel = new SmartPanel();
	hPanel.SetTitleFormat(_, "%T", "CMD_TEST_MENU_TITLE", client);
	hPanel.DrawItemFormat(_, "%T", "One", client);
	hPanel.DrawItemFormat(_, "%T", "Two", client);
	hPanel.SendToClient(client, PanelHandler_Test, 20);
	delete hPanel;
	return Plugin_Handled;
}
Log:
Code:
L 04/20/2018 - 22:32:58: [SM] Exception reported: Translation failed: invalid client index 1162756432
L 04/20/2018 - 22:32:58: [SM] Blaming: pls.smx
L 04/20/2018 - 22:32:58: [SM] Call stack trace:
L 04/20/2018 - 22:32:58: [SM]   [0] VFormat
L 04/20/2018 - 22:32:58: [SM]   [1] Line 21, C:\Games\tf2server\tf\addons\sourcemod\scripting\include\pls/menus.inc::SmartPanel.SetTitleFormat
L 04/20/2018 - 22:32:58: [SM]   [2] Line 891, C:\Games\tf2server\tf\addons\sourcemod\scripting\pls.sp::CMD_Test
SetTitleFormat method source:
Code:
public void SetTitleFormat(bool onlyIfEmpty = false, const char[] text, any ...) {
	char sTitle[MAX_MENU_TITLE_LENGTH];
	VFormat(sTitle, MAX_MENU_TITLE_LENGTH, text, 3);
	this.SetTitle(sTitle, onlyIfEmpty);
}
Also i have problem with some HEX strings (colors). For example i have KeyValues config:
Code:
"Senior Member"
{
	"color" "006400"
	"kills" "6500"
}
I have tried to debug and then console said "sName: Senior Member | HEX: 6400 | Kills: 6500".
Why 6400 instead of 006400?

This also appears on 9400D3 (output: 9400000) and 4D7455 (output: 1.#INF0)
__________________

Last edited by MAGNAT2645; 04-22-2018 at 03:19. Reason: Solved
MAGNAT2645 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 04-20-2018 , 16:52   Re: Translation and string problems
Reply With Quote #2

For the translation problem, there's a SM bug. VFormat gets things wrong when called from a methodmap function inside a methodmap you have to use "new" with.

A workaround until SM is fixed is to make VFormat's last parameter one higher than you'd expect. In the code you pasted, you need to pass 4 instead of 3.

For keyvalues, the first issue is just how they work. There are unexpected conversions between types, so at some point it's probably treated like a number and loses the leading zeroes. This is code from Valve's SDK, so SM isn't going to change it. The for the other two values, you should show your code.
Fyren is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 04-20-2018 , 23:43   Re: Translation and string problems
Reply With Quote #3

I can't show all code because my plugins are private (and because my code is very large and consists of several parts (other .sp sources)) but i can post some parts (with edits that will hide some names) where this happens.
About KeyValues:
Code:
kvRanks = new KeyValues("RankList");
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/pls/ranks.cfg");
kvRanks.ImportFromFile(sPath);
g_alRanks[PlayerRankData_HEX] = new ArrayList(ByteCountToCells(8));
MAX_PLAYER_RANK = -1;
kvRanks.GotoFirstSubKey();
do {
	char sName[MAX_PLAYER_RANK_LENGTH], sHEX[8];
	kvRanks.GetSectionName(sName, MAX_PLAYER_RANK_LENGTH);
	kvRanks.GetString("color", sHEX, 8, "FFFFFF");
	int iKills = kvRanks.GetNum("kills");
	g_alRanks[PlayerRankData_Kills].Push(iKills);
	if (!String_IsEmpty(sName))
		g_alRanks[PlayerRankData_Name].PushString(sName);
	if (!String_IsEmpty(sHEX))
		g_alRanks[PlayerRankData_HEX].PushString(sHEX);
	#if defined DEBUG
	PLS_Debug(DEBUG_LOG_MAIN, true, true, "Registered rank %i (Name: %s | Color: #%s | Kills needed: %i)", MAX_PLAYER_RANK + 1, sName, sHEX, iKills);
	#endif
	MAX_PLAYER_RANK++;
} while (kvRanks.GotoNextKey(false));
delete kvRanks;
KV Config (with problematic colors only):
Code:
"RankList"
{
	"Test I"
	{
		"color" "4D7455"
		"kills" "3000"
	}
	"Test II"
	{
		"color" "006400"
		"kills" "6500"
	}
	"Test III"
	{
		"color" "9400D3"
		"kills" "25000"
	}
}
About VFormat, should i increase varpos from 3 to 4 ?
Like:
Code:
VFormat(sTitle, MAX_MENU_TITLE_LENGTH, text, 4);
(It seems that SM gets string (instead of client index) as second argument for translating so there very large numbers like "Translation failed: invalid client index 1431192909", "Translation failed: invalid client index 1162756432" etc.
__________________

Last edited by MAGNAT2645; 04-20-2018 at 23:45.
MAGNAT2645 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 04-21-2018 , 00:24   Re: Translation and string problems
Reply With Quote #4

Using this test plugin:

PHP Code:
public void OnPluginStart() {
        
KeyValues kvRanks = new KeyValues("RankList");
        
char sPath[PLATFORM_MAX_PATH];
        
BuildPath(Path_SMsPathsizeof(sPath), "data/kv.txt");
        
kvRanks.ImportFromFile(sPath);
        
kvRanks.GotoFirstSubKey();
        do {
                
char sName[32], sHEX[8];
                
kvRanks.GetSectionName(sNamesizeof(sName));
                
kvRanks.GetString("color"sHEXsizeof(sHEX), "FFFFFF");
                
int iKills kvRanks.GetNum("kills");
                
PrintToServer("%s %s %i"sNamesHEXiKills);
        } while (
kvRanks.GotoNextKey(false));
        
delete kvRanks;

I get this output, which is what I'd expect:

Code:
Test I 4D7455 3000
Test II 6400 6500
Test III 9400D3 25000
As for what to do about losing the leading zeroes, either pad it yourself to get 6 characters or use the SMC functions instead of KV.

Quote:
Originally Posted by MAGNAT2645 View Post
About VFormat, should i increase varpos from 3 to 4 ?
Yes. If that methodmap uses VFormat in other non-static functions, you'll have to increase each.
Fyren is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 04-21-2018 , 00:48   Re: Translation and string bugs
Reply With Quote #5

I did it with other methods like AddItemFormat, DrawItemFormat and now i got this error (seems that SetTitleFormat fixed?):
L 04/21/2018 - 096:17: [SM] Exception reported: Translation string formatted incorrectly - missing at least 1 parameters
L 04/21/2018 - 096:17: [SM] Blaming: pls.smx
L 04/21/2018 - 096:17: [SM] Call stack trace:
L 04/21/2018 - 096:17: [SM] [0] VFormat
L 04/21/2018 - 096:17: [SM] [1] Line 101, C:\Games\tf2server\tf\addons\sourcemod\script ing\include\pls/menus.inc::SmartMenu.AddItemFormat
L 04/21/2018 - 096:17: [SM] [2] Line 9, C:\Games\tf2server\tf\addons\sourcemod\script ing\pls/clientprefs.sp::ShowSettingsMenu
L 04/21/2018 - 096:17: [SM] [3] Line 3, C:\Games\tf2server\tf\addons\sourcemod\script ing\pls/clientprefs.sp::CookieMenuHandler_Settings

Error appears in this function:
Code:
static void ShowSettingsMenu(int iClient) {
	SmartMenu hMenu = new SmartMenu(MenuHandler_Settings);
	hMenu.SetTitle("%T", "MENU_SETTINGS_TITLE", iClient);
	hMenu.AddItemFormat("HudEnable", _, "[%T] %T", g_bHudEnabled[iClient] ? "ENABLED" : "DISABLED", iClient, "MENU_SETTINGS_HUD_ENABLE", iClient);
	hMenu.AddItemFormat("AimEnable", _, "[%T] %T", g_bAimEnabled[iClient] ? "ENABLED" : "DISABLED", iClient, "MENU_SETTINGS_AIM_ENABLE", iClient);
	hMenu.ExitButton = true;
	hMenu.ExitBackButton = true;
	hMenu.Display(iClient, MENU_TIME_FOREVER);
}
EDIT: This is my problem that i have used 1 unwanted parameter in phrases.txt. So this fixed. Now i must do something with colors.

Colors are fine (just replaced some numbers with letters) and menu translation fixed but some menus dont work anyway.
Like:
Code:
hMenu.AddItemFormat(sKey, _, "%T", "MENU_ADMIN_PREFIX", iClient, sKey);
Translation phrase:
Code:
"MENU_ADMIN_PREFIX"
{
	"#format" "{1:s}"
	"ru" "[Админ] {1}"
	"en" "[Admin] {1}"
}
throws Translation failed: invalid client index 1431192909.

Seems to be fixed
__________________

Last edited by MAGNAT2645; 04-21-2018 at 02:05.
MAGNAT2645 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 10:44.


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