Pages: [1]
  Print  
Author Topic: TCODText::reset()  (Read 2022 times)
cottog8444
Apprentice
*
Posts: 4


View Profile
« on: July 22, 2014, 02:48:00 pm »

I am working with TCODText objects to allow a user to input a character name. If the name isn't acceptable, I'm using TCODText::reset() to hopefully clear the text object and allow the user to input a new name.

The text object's contents are deleted, but the cursor stays where it would be if the text object was still full and if the user attempts to input a name the same length or longer than the old name, the Text object is behaving as if its length was the length of the bad name.

The above sounds complicated, but let's say I input "Vegeta" and the game rejected it. If I then wanted to input "Vegeto," I could type "Veget" (or any other 5-letter sequence), but any subsequent input (a 6th letter) would cause the other letters, starting with 'V,' to become corrupted in turn. In this exact example, all of the letters become 'e.'

In light of all this, I am wondering if there is something beyond reset() that needs to be done to a TCODText object in order to clear it/prepare it for new input.

I am working with C++, but I figure any light being shed on how TCODText::reset() works would be useful for users of any language, as I'm pretty sure textfield stuff is currently undocumented.
Logged
Frednotbob
Defender
*****
Posts: 71


View Profile
« Reply #1 on: March 24, 2015, 08:05:06 am »

If you're still having problems:

If you're storing the name in an array, you're most likely exceeding the space you've allocated for the array elements; if you have a five-character array and try to input six characters, the array will overflow and print whatever data is next in that block of memory.

You can see the effect if you 'top out' the score in the original NES version of Mario Bros; eventually, the score will go from numbers to random symbols, because there's no memory allocated to display the extra digit.
Logged
cottog8444
Apprentice
*
Posts: 4


View Profile
« Reply #2 on: March 24, 2015, 09:24:54 pm »

Thanks for the reply. I am not working with arrays (at least, not directly).

 I am working with TCODText objects, which are an undocumented feature in 1.5.1, but should possibly be documented in 1.5.2.

I guess I will source-dive to find the solution, but TCODText::reset() (in C++), doesn't appear to be doing what I had hoped/assumed it would do.
Logged
Pages: [1]
  Print  
 
Jump to: