3

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:

Wrong Text

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.

enter image description here

Msg1

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
AStopher
  • 4,207
  • 11
  • 50
  • 75
  • 1
    I had a problem like this using MFC text widget. It seems MFC does did not align the output. Could this be the same Issue your having? – andre Jul 15 '13 at 21:03
  • Could be. If it is, watch this space! :) – AStopher Jul 15 '13 at 21:06
  • Could you paste (or link to) the CentreTextForConsole function? – Etan Reisner Jul 16 '13 at 12:26
  • @EtanReisner: As said before, this is not to do with this function and is not about the centering of the text. It is about the inverted text. – AStopher Jul 16 '13 at 16:20
  • @AlexanderStopher: OK, let me explain how Stack Overflow *doesn't* work. It doesn't work by you editing your question to put the solution in the question. SO is a Q&A site, *not a forum*. Questions go at the top, answers at the bottom. You don't put answers in questions. If an answer solves your problem, you accept it and upvote it. – Nicol Bolas Jul 21 '13 at 12:46
  • Nicol's right. If you want to leave an answer that highlights the solution to your question, please do so as an actual answer. This makes things a lot easier to read for future visitors. Solutions shouldn't be placed within the body of the question. – Brad Larson Jul 25 '13 at 16:47

2 Answers2

2

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
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • You've made it here: http://online-gaming-world.de/index.php?page=Thread&postID=2914#post2914. :) – AStopher Jul 21 '13 at 09:38
  • @AlexanderStopher: "*It actually says that you can create a new topic on your problem as long as you edit it sufficiently, which I did.*" [That rather depends on who you ask.](http://meta.stackexchange.com/questions/189732) There seems to be some disagreement about how that's supposed to work. Also, your edits were in no way sufficient to make the new question different. As evidenced by the fact that I provided this answer to your old question without ever having read it in any detail. – Nicol Bolas Jul 21 '13 at 12:49
1

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.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • No, this doesn't fix the problem and is not to do with the code used to center. The image and text code is just an example; this happens in almost every text block that is sent. – AStopher Jul 16 '13 at 07:43
  • Can you give us an example pair that doesn't have that bug and still displays your incorrect output? Because in the code snippet and image above that extra space is almost certainly the bug. – Etan Reisner Jul 16 '13 at 12:26
  • Is something wrong in that commands image? As for the other image the only thing I can see offhand is that the bottom line isn't centered. Is that the issue? Does it happen with lines that don't have fancy formatting? – Etan Reisner Jul 16 '13 at 15:24
  • Actually, looking at the other question about this that you posted the other day I wonder if the problem is that your centering function is taking formattting strings into account in the length of the message and so every embedded color string is going to de-center your message by a character or two. – Etan Reisner Jul 16 '13 at 15:25
  • The problem isn't the centering code, as stated in the initial post. – AStopher Jul 16 '13 at 15:53
  • There is nothing wrong in the 'Commands' image; I'm just using it to demonstrate that it works perfectly sometimes and sometimes not. – AStopher Jul 16 '13 at 15:55
  • If the issue isn't the mis-centering of the contents then what is the issue? If the issue is the mis-centering of contents then how is the centering code not the problem (or at least related to the problem)? – Etan Reisner Jul 16 '13 at 15:56
  • 1
    Is the issue the inversion of contents as compared to the function call order? – Etan Reisner Jul 16 '13 at 15:56
  • That's precisely what it is. If there are any problems with the centering of the text, I'll sort it later. – AStopher Jul 16 '13 at 16:01
  • When this happens does it always invert all the messages completely? Or is it a "random" disordering of the messages? – Etan Reisner Jul 16 '13 at 16:19
  • It always inverts the messages, apart from a few occasions (such as in the 'Commands' screenshot) where it does not invert. – AStopher Jul 16 '13 at 16:25
  • See the new topic that I just opened. Please read first and do not assume that I'm talking about the centering, which I am not. – AStopher Jul 21 '13 at 08:17