Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Hobo Joe on Mon 05/01/2009 16:25:46

Title: How to make non-blocking scrolling text?
Post by: Hobo Joe on Mon 05/01/2009 16:25:46
I don't know how best to explain what I want, so I made a video to show you.

http://www.youtube.com/watch?v=jfOxpOrbP0I

Looking for text in a game that can function like it does in the old KQ. Any help would be much appreciated.
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Mon 05/01/2009 17:25:59
There's no simple, straigthforward solution to this.
You could use a Listbox and a Textfield for the line the player can type into.
Then you'd need an array to keep track of the 4 or 5 lines, write some sort of echo() function that'll print the text word by word, taking care of the line breaks.
You'd probably have to adjust the listbox's and textfield's size and position whenever necessary and so on.

I might try this later but I don't have time right now.
Title: Re: How to make non-blocking scrolling text?
Post by: Hobo Joe on Mon 05/01/2009 17:27:43
Oh, sorry, forgot to mention: I'm not going to be using a parser. It's point and click. Just want the text to DISPLAY like that. Sorry again for not being more specific.
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Mon 05/01/2009 17:28:20
It's more or less the same, just without the textfield.
Title: Re: How to make non-blocking scrolling text?
Post by: Hobo Joe on Mon 05/01/2009 18:58:16
Okay. I'll fiddle around. I can get a listbox to display, but not much else. I'm not really clear on how arrays work and I don't know what an echo command is either. Sorry!
Title: Re: How to make non-blocking scrolling text?
Post by: Dualnames on Mon 05/01/2009 19:03:01
It's possible thing is I'm not in the time to do it. How about you wait  a little longer?

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=32630.0
The link might be of use.
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Mon 05/01/2009 20:53:59
I meant you'd have to use a custom echo() function to display text, i.e. write the function yourself. Of course you can call it whatever you want, echo is just a common name for the process of / command for outputting text.

Arrays are pretty simple, string arrays are still a bit more complicated though.
Like I said, I might post working code if I get to try out some things later.
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Tue 06/01/2009 06:31:30
*bump*

Download the module, GUI and demo game. (http://www.2dadventure.com/ags/LineDelay.zip)

-Import the GUI and module into your game, make sure the module is above the global script in the script list.

-put this line in game_start in the global script:
  if (LineDisplay.Init(gLineDisplay_MG, 4, 0)) Display(LineDisplay.Err_Message());

-To use your own GUI, put labels on it that use subsequent ID numbers.
Then adjust the parameters, e.g. if your GUI is called "gScrolltext" and you want to display the text in five labels with IDs 3 to 7, you have to call LineDisplay.Init(gScrolltext, 5, 3) in the code line above.

-The default speed is 8 words per second, i.e. the default delay is 5 game loops in between words. You can change that by calling e.g.
  LineDisplay.SetDelay(20);  // two words per second
(by default, 1 second == 40 game loops)

The module will warn you if you didn't set up the GUI and its labels correctly; it won't quit the game though.

Edit: It was really late yesterday, or rather pretty early...

Actually use the module by employing these two commands:

DisplayLD(String message);
Adds the message to the buffer and displays it, word by word, in the GUI.

Character.SayLD(String message);
Same as above, but "CharacterName: " is put before the message.
Title: Re: How to make non-blocking scrolling text?
Post by: Hobo Joe on Tue 06/01/2009 19:41:15
That is absolutely and utterly perfect. You are my hero. Thank you so much!
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Tue 06/01/2009 20:00:06
You're welcome; I was eager to write more than three lines of code for a change anyway :)
Title: Re: How to make non-blocking scrolling text?
Post by: Hobo Joe on Wed 07/01/2009 05:58:54
Just one more thing: Is there a way I can make it so the text disappears when you walk off the screen?

EDIT: Crap. I've hit a snag. I got an "Increase buffer size" error. It's weird though, I have 2 identical scripts set up in 2 different rooms, it works fine in the first and then gives me that error in the second one. I'll keep looking at it to see what's wrong, but help on that would be appreciated also.
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Wed 07/01/2009 15:56:50
I've added a function:
LineDisplay.Clear()
Call it anytime to clear the lines and the buffer.
(You could put it inside on_event(...) and call it upon eEventLeaveRoom)

The buffer size can be set at the top of the module script; there's a define line.
I've increased it from 50 to 200, just increase it further until you don't get the error.

http://www.2dadventure.com/ags/LineDisplay_v0.2.zip

(The buffer is an array of strings that gets filled up one by one every time a DisplayLD or SayLD is called. Once a line is fully printed, the string is removed from the buffer, freeing up one slot. Calling many consecutive DisplayLDs or SayLDs, together with a high word delay can result in a full buffer. The downside of increasing the buffer to, say, 1000 is that every saved game is 1000 times string space bigger in file size. String space is at least 200 bytes I believe, so a buffer of 1000 adds 200k to every save.)
Title: Re: How to make non-blocking scrolling text?
Post by: Hobo Joe on Wed 07/01/2009 21:02:47
The buffer exploded because the function hHotspot5_WalkOn() was firing repeatedly for some reason. I changed it so the character disappears and an object animates there instead and that fixed it. All good now. Thanks!
Title: Re: How to make non-blocking scrolling text?
Post by: Khris on Wed 07/01/2009 22:06:18
In the future, you should use a region and the step on event (because it will only be called once).