TextBox word-wrap, and faster typing

Started by KingMick, Fri 21/04/2006 10:58:50

Previous topic - Next topic

KingMick

I'm noticing two problems with the textbox I created for my game.

(1) I want the player to be able to enter up to 90 characters, which means that I'd like to have the words wrap around.  Unfortunately it appears that textboxes will not allow you to do this.  Is there some other way to either get the textbox to word-wrap, or to provide another means for the player to enter text that DOES word-wrap?

(2) I've never used textboxes in AGS before, but I'm noticing that the typing rate is incredibly slow.  In the time it takes me to type 6 letters, AGS has only displayed the first one.  It takes 5 or six seconds before a full line of text shows up on the screen.  Maybe this is just my coputer?  Is there some way to make this work faster?  Here's all of what I assume the relevant information would be:

game resolution & color: 800 x 600, 32 color debth
GUIs visible: 2. The first has 14 items, the second (with the textbox) has 2.
music playing: NONE!
repeatedly_execute: Just one if/then statement to check if a specific bool variable is true, and declare it false if it is.

I'm running a 1.0 Ghz machine so maybe that's the problem right there.  Considering I have no music playing at all, I can't imagine how slow the text will enter once the music is actually playing!

Any help would be greatly appreciated!

Gilbert

1. I think currently there's no good way to make text texts wraping around (it might be possible to make your own custom "textbox" using a GUI label and some scripting in on_key_press() to parse key pressed to add to the label though).

2.
Quote from: KingMick on Fri 21/04/2006 10:58:50
I'm running a 1.0 Ghz machine so maybe that's the problem right there.
Unfortunately I think that's probably the reason for it, try turning on FPS display (using Debug(4,1) ) to see if your computer can run it at full frame rate, AGS is not very optimised for this highest setting, since originally it's not designed for making games using this res, and it doesn't even use any graphics acceleration at the moment.

KingMick

Wow thanks for the fast response Gilbot!  That's what I love about these forums...

If it's just my machine that's causing the slowdown, then that's ok.  Most people's computers are twice as fast as mine anyway, so that's no big deal.  I'll probably include a disable-the-music-while-writing-in-the-journal option for people with slow comps.

Hmmm, no built-in way to do user-inputted word-wrap, eh?  That sounds like something they ought to add.  I wonder if there's a module or plug-in that would do it.  I'll have to look around.  Otherwise, I'll have to figure out how to do it myself.  Maybe change the gui to have 6 labels that get replaced with textboxes each time you hit enter from the last one, or something like that.  It would be easier for a newbie like me than the on_key_press parsing idea.  I guess the textbox could send its text to one of the labels, then change its location, until the sixth time when the program bundles all 6 strings together and sends the whole thing to the appropriate function...I'll have to think about this some more.

Anyway, thanks for your help!

GarageGothic

#3
Quote from: KingMick on Fri 21/04/2006 11:14:41It would be easier for a newbie like me than the on_key_press parsing idea.

the on_key_press parsing idea is excellent, and it's very easy to achieve. Probably you will find it among the simplest things in your whole script. Here's the on_key_press code for the search textboxes in my own html-like system. This is old and messy code based on strings rather than Strings, but I don't have time to update it right now:

Code: ags

if ((keycode >= 1) && (keycode <= 127) && (keycode != 8) && (keycode != 13) && (keycode != 9) && (keycode != 27) && (IsKeyPressed(405) == false) && (IsKeyPressed(406) == false)) {
		string searchchar;
		StrSetCharAt(searchchar, 0, keycode);
		if ((IsKeyPressed(403) == false) && (IsKeyPressed(404) == false)) StrToLowerCase(searchchar);
		string lengthtest;
		StrCopy(lengthtest, searchline);
		StrCat(lengthtest, searchchar);	
		if (GetTextWidth(lengthtest, 7) < (Game.SpriteWidth[442] - 3)) StrCat(searchline, searchchar);
		}
	else if ((keycode == 8) && (StrLen(searchline) > 0)) { //BACKSPACE
		StrSetCharAt(searchline, (StrLen(searchline)-1), 0);
		}


All the conditionals in the beginning are there to make sure that the char is a proper character and that CTRL isn't held down. The reason the character is parsed as a string is to make is upper or lower case depending whether shift is held. The SpriteWidth check is only used because the textbox background is a sprite.

If you used this method, but with Strings instead of strings, you could allow the label to do it's own linebreaking, so no worries about that. As for faster typing - it seems strange that this should be slow, since I assume the game is paused while the player types. You could try to SetGameSpeed(int speed) to more than the default 40 fps. But of course this will have no effect if the slowdown is caused by your CPU.

SSH

In my Credits module you will find a function tucked away that inserts linebreaks in a string to make it word-wrapped. This may help.
12

KingMick

Oooo, both of these last two suggestions are making me reconsider my 6-labels-and-a-textbox-input-screen idea.  I'll have to fool around some more with this stuff, and I'll definitely have a look at that module.

Thanks guys for helping me out so much with this!  The journal looks great, btw--hopefully I'll have some screenshots up soon in the My-Game's-Not-Done-Yet-But-Hopefully-Soon forum, whatever it's called.

KingMick

Ok I'm definitely going to give the text-parsing thing a shot, if I have any difficulties I'll post them here.

Meanwhile, another question before I begin--do you guys anticipate that a well-written text-parsing code based on the premise of Garage's code up there would go faster than the textbox-typing, or slower?  As I stated before, my comp appears to be having some trouble with the textbox thing :(

Scorpiorus

#7
Quote from: KingMick on Sun 23/04/2006 01:55:17Meanwhile, another question before I begin--do you guys anticipate that a well-written text-parsing code based on the premise of Garage's code up there would go faster than the textbox-typing, or slower?

Depends on whether it is a performance issue. If that's it, there probably will be a little difference.

Does your cursor move choppy?
Anyway, you should check how many frames per second (FPS) you get, as Gilbot suggested. Put "Debug(4,1);" within the game_start function from the main global script:

function game_start() {
Ã,  Ã, Debug(4,1);
}

And make sure the "Debug mode" option is ticked (see editor general settings pane).

So what's the number next to FPS at the bottom left corner of the screen when your run the game?

SMF spam blocked by CleanTalk