Game Development Community


#1
01/07/2005 (10:07 am)
There is not.
#2
01/07/2005 (10:18 am)
K thanks. I'll probably add one then. Is this useful for other people or do you have another way of working that speeds things up?

I find myself exec'ing the same script over and over again when I am testing something, usually I just need to do it in one run, then I can use the current history, but sometimes I accidentally exit out of the entire game or find I need to go try something else and then type the long string again.
#3
01/07/2005 (10:23 am)
CTRL + C then CTRL + V can help (I use that often) ;)
#4
01/07/2005 (11:27 am)
Yes ctrl c and ctrl v are good...as long as you have what you want in an easy place to copy.


awwww I thought I was going to have this easy. I wrote the code for dumping and loading the Gui Text edit controls history and the dump works fine but the read didn't work...then I saw:
bool FileObject::openForRead(const char* /*fileName*/)
{
   AssertFatal(false, "Error, not yet implemented!");
   return false;
}

d'oh!
#5
01/07/2005 (11:29 am)
Ahh I guess I should be using the FileStreams instead of the FileObject ok.
#6
01/07/2005 (11:31 am)
Really ?

this the same function called with the script commands

%file = new FileObject(); 
%file.openForRead(%filename)

because I just used it and it works perfectly fine
#7
01/07/2005 (11:46 am)
That's because the Console function uses a different source function:

ConsoleMethod( FileObject, openForRead, bool, 3, 3, "(string filename)")
{
   return object->readMemory(argv[2]);
}
#8
01/07/2005 (11:47 am)
Hmm. yes that snip was from my FileObject.cc source file. This is pure from TGE 1.3 cvs checkout, a while back.

could you peek at your source and see what you have?
-c
#9
01/07/2005 (11:48 am)
Ahhh ok

here's the console method:
ConsoleMethod( FileObject, openForRead, bool, 3, 3, "(string filename)")
{
   return object->readMemory(argv[2]);
}

I'll try that.
#10
01/07/2005 (12:10 pm)
@Owen: you beat me to it! :)


ok here it is for anyone who wants it, hopefully a timesaver for somebody else too.

at the top of GuiTextEditCtrl.cc

#include "core/fileObject.h"

new functions and console functions somewhere in GuiTextEditCtrl.cc

void GuiTextEditCtrl::dumpHistory(const char* filename)
{
   Con::printf( "Dumping GuiTextEditCtrl: %s history to %s...", getName(), filename );
   FileObject file;
   if ( !file.openForWrite( filename ) )
   {
	   Con::warnf("unable to open file for write: %s", filename);
      return;
   }

   if (mHistoryBuf)
   {
      for (S32 i = 0; i < mHistorySize; i++)
	  {
		  if(mHistoryBuf[i][0])
		    file.writeLine( (const U8*) mHistoryBuf[i]);
 	  }
   }
   else
   {
	  Con::warnf("no history buffer available");
   }

   file.close();
   
   
}
void GuiTextEditCtrl::loadHistory(const char* filename)
{
   Con::printf( "loadHistory GuiTextEditCtrl: %s history from %s...", getName(), filename );
   FileObject file;
   if ( !file.readMemory(filename ) )
   {
	   Con::warnf("unable to open file for read: %s", filename);
      return;
   }

   while(!file.isEOF())
   {
	    const char* tmp = (const char*) file.readLine(); 
		if(tmp[0] && tmp[0] != '\n' && tmp[0] != '\r')
		  updateHistory( tmp, false );
   }
 
   file.close();
   

}

ConsoleMethod( GuiTextEditCtrl, dumpHistory, void, 3, 3, "(string filename)"
              "Dump the history to a file, use loadHistory to reload one of these files.")
{
      object->dumpHistory( argv[2] );
}

ConsoleMethod( GuiTextEditCtrl, loadHistory, void, 3, 3, "(string filename)"
              "Load the history from a file, use dumpHistory to create one of these files.")
{
      object->loadHistory( argv[2] );
}


and in GuiTextEditCtrl.h somewhere in the public section of the class
void dumpHistory(const char* filename);
   void loadHistory(const char* filename);

then in your module's main.cs file at the bottom of function onStart()
if(isObject(ConsoleEntry))
   {
	   ConsoleEntry.loadHistory("YOURMODULENAME/client/consoleHistory.txt");
   }
   else
   {
	   echo("---no ConsoleEntry not loading history");
   }
and near the top of function onExit()
if(isObject(ConsoleEntry))
   {
	   ConsoleEntry.dumpHistory("YOURMODULENAME/client/consoleHistory.txt");
   }
   else
   {
	   echo("---no ConsoleEntry not dumping history");
   }
#11
01/11/2005 (8:31 am)
Neat thing, gonna put this on my todolist.
#12
04/26/2006 (2:22 pm)
Bump... seems like this didn't make it into 1.4. Maybe it will make 1.4.x?
#13
07/10/2006 (2:15 am)
Has anyone got this to work with TGE 1.4? I got a compile error that I fixed (or so I thought). When I check the console history the only entry is a "0". I was getting an error about converting const char* to StringBuffer*.

I replaced
updateHistory( tmp, false );

with:
updateHistory( &StringBuffer(tmp), false );

Doing that I was able to compile but it doesnt work. What is the proper way to convery a const char* to StringBuffer?
#14
07/16/2006 (1:59 pm)
*bump*

Anyone got this working with 1.4?
#15
07/18/2006 (1:43 pm)
Hi Peter, I'm not using TGE 1.4 so I haven't seen the problem, but doing a quick look at the code, it looks like itmight work if you make a local String Buffer first..
so try doing a
StringBuffer tmpSB;
tmpSB.set(tmp);
then call 
updateHistory(&tmpSB, false);
not sure but I see them loading StringBuffers with char*'s that way in other places in the 1.4 code.


or instead of tmpSB use the existing mTextBuffer (this looks like it might be the better thing to do)
mTextBuffer.set(tmp);
updateHistory(&mTextBuffer, false);


let me know if it works!

hmm actually thinking about it some more, I bet you might just need to rewrite the load and dump history functions, unless you see stuff in the history txt file