Game Development Community

Console history and GuiTextEditCtrls

by Rubes · in Torque Game Engine · 01/23/2008 (10:31 pm) · 7 replies

Just a quick question for those in the know:

My game uses the MessageHud (part of the ChatHud gui) for text command entry, and I would like it to keep a history that can be recalled using the up and down arrow keys the same way that is currently implemented for the console. The MessageHud doesn't appear to recall history with the up and down arrow keys.

After looking through the engine code, the storage and recall of historical entries with the arrow keys seems to be built into the GuiTextEditCtrl code. The console is a GuiConsoleEditCtrl, which is just a specialized GuiTextEditCtrl, but I can't seem to figure out why it works for the console and not for the MessageHud. Perhaps I missed something, but it doesn't appear that the small differences between the GuiConsoleEditCtrl and GuiTextEditCtrl would explain this. And I can't find anything in the script implementation to explain it either.

Anyone?

#1
01/24/2008 (7:52 am)
Check the %obj.historySize field, set it to be something like 100 and try.
That's the field that keeps the "amount of lines of entered text", check the sources of how it's handled to get more info
#2
01/24/2008 (8:31 am)
Thanks, I did notice that. I had already set it to 20, but that didn't do anything. The console historySize is also set to 20, and that seems to work fine for the console.
#3
01/24/2008 (9:18 am)
Rubes, are you sure ?
the following seems to have history just fine in our tge 1.3.5-based codebase, and i can't imagine it's changed much in 1.5:

new GuiTextEditCtrl(foobar) {
      position = "0 0";
      extent = "300 26";
      altCommand = "$ThisControl.setText(\"\");";   // not actually necessary
      historySize = "200";
   };

i do notice that using the GuiEditor to change the history size of an existing GuiTextEditCtrl from zero to something positive seems to result in a crash in both my codebase and the stock TGE 1.4 demo.
#4
01/24/2008 (10:05 am)
Yeah, I'm pretty sure.

I made a few changes to the script code for the MessageHud, but I've been over it many times and I can't see anything that might have caused this issue. I do notice that if I press the up or down arrow, it clears out the current entry line -- like maybe it's trying to access a history buffer that is empty or something. I can't tell for sure.

I'm guessing the reason for your crash might have something to do with how the engine code sets up the history buffer. I think the buffer is set up when the control is first added to the scene, but only if the historySize is >0. So if it starts out at 0, changing it likely causes the control to try and access a buffer that doesn't exist, since it wasn't set up. Just a guess, though.
#5
01/24/2008 (10:10 am)
Hm, dunno.
try adding the sample i posted there ?

crash - yeah, prolly something like that. not my lookout today, tho.
#6
01/24/2008 (10:13 am)
Actually, that might be a good idea, just to try adding a new GuiTextEditCtrl separate from the MessageHud and see if it handles the history buffer. Should have tried that.
#7
01/24/2008 (1:45 pm)
The really bizarre part of all of this, is that if you open up the generic starter.fps game, the MessageHud does actually save and recall history like it should. I made some changes to the MessageHud script code, but for the most part it was taken verbatim from the starter.fps code. And the creation of the MesageHud in ChatHud.gui is exactly the same as in starter.fps.

In any case, I went ahead and replaced both of my /client/ChatHud.cs and /client/MessageHud.cs with the originals from the starter.fps kit, and it still did not save or recall history. WTF?

I have no idea what else might be interfering with this.