Reputation: 4551
I have the following code to send a block of text to a users' game console (Crysis Wars):
CMCCPlayer(player, "================================================================================================================");
CMCCPlayer(player, "$4#### ### ### ###### ####");
CMCCPlayer(player, "$4## ### ### ## ## ##");
CMCCPlayer(player, "$4## ### ### ## ##");
CMCCPlayer(player, "$4## ### ##### ###### ### ##");
CMCCPlayer(player, "$4## ### ### ## ##");
CMCCPlayer(player, "$4## ### ### ## ## ## ");
CMCCPlayer(player, "$4#### ### ### ###### ####");
CMCCPlayer(player, "================================================================================================================");
But I get this result:
This problem has practically plagued the Crysis Wars developer community, and there have been no real solutions to this. The code formats fine if I do it straight from C++ as opposed to Lua to C++,, so this must be a problem Lua-side.
I have tried timing the messages to 1ms apart, and this resulted in some messages going missing (probably because recent messages override the old ones). Do you guys have any suggestions or solutions to this issue? If you provide a working solution, you'll be pretty famous within the Crysis Wars developer community as you would have solved a pretty annoying bug :). I would offer some of my reputation but unfortunately I awarded the bounty this morning to someone for solving another issue.
Function code for sending the messages:
function CMCCPlayer(player, msg)
g_gameRules.game:SendConsoleMessage(player.id, g_gameRules.game:CentreTextForConsole(msg));
end
If this helps for anything, here's the C++ SendConsoleMessage code:
int CScriptBind_GameRules::SendConsoleMessage(IFunctionHandler *pH, ScriptHandle playerId, const char *msg)
{
CGameRules *pGameRules=GetGameRules(pH);
if (!pGameRules)
return pH->EndFunction();
int channelId=pGameRules->GetChannelId((EntityId)playerId.n);
pGameRules->SendTextMessage(eTextMessageConsole, msg, eRMI_ToClientChannel, channelId);
msg=0; //Null the message.
return pH->EndFunction();
}
Edit:
Please note that this isn't to do with the text used to center and that the image and text block below is only provided as an example; this issue occurs on every piece of code that is sent.
Upvotes: 3
Views: 248
Reputation: 474126
So you're saying that a sequence of these functions always results in output that is the exact opposite of the function order. So... just send the data in the reverse order. This will therefore double the reversal and submit the data in the expected order.
There are numerous ways of doing this. You can create a simple Lua function that takes an array of strings and broadcasts them in reverse order:
function BroadcastToPlayer(player, strings)
for i = #strings, 1, -1 do
CMCCPlayer(player, strings[i]);
end
end
You can augment this to take the strings as either an array or a variadic series of strings, building the array in-situ:
function BroadcastToPlayer(player, ...)
local test = ...
if(type(test) == "string") then return BroadcastToPlayer(player, {...}) end
for i = #strings, 1, -1 do
CMCCPlayer(player, strings[i]);
end
end
You can even create a simple Lua object that is given strings to be sent, and then call it to send all of the stored strings.
function CreateStringMan()
local man = {}
function man:add(str)
self._strings = self._strings or {}
self._strings[#self._strings + 1] = str
end
function man:CMCCPlayer(player)
for i = #self._strings, 1, -1 do
CMCCPlayer(player, self._strings[i]);
end
self._strings = {} --clear the strings
end
return man
end
Upvotes: 2
Reputation: 81012
That output is inverted from your input. If you look at your input carefully you will notice that your second to last content line is one character longer than your other lines. That will cause it to be centered on screen differently. Try removing that extra space and seeing if that fixes the problem.
Upvotes: 1