Text game advice needed... line breaks.

BlitzPlus Forums/BlitzPlus Programming/Text game advice needed... line breaks.

DRH(Posted 2014) [#1]
I'm trying to take my text game engine I wrote in blitz 3d and use all the nifty menus and labels and such in blitz plus to make it faster and generally easier to code... however..

I have a problem. I'm using a system of types that hold strings that are descriptions of areas and such and they have to appear in order as well as word wrap. I need to break them up with line breaks but I'm confused as to how to tell it to do so easily.

The engine searches for event descriptions and then writes them in order, then it is supposed to move onto the area you are in, then shop details, and etc.

So.. this may be a very simple thing I'm overlooking.. but..

How do I tell the label to include a line break? I want to include it into the string if possible, but if there is a fast way to at least line break between strings then I can have it work.

like( example)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
As Miss Brusker left the room you could tell she wasnt pleased with this year's class. But reguardless of her expectations, or lack of, you knew you would proove her wrong...

(break)

You are in classroom 1-A of the alchemy department. The room is bright and spacious with many desks and other students talking.

(break)

One of your classmates is looking at you, perhaps they want to ask you something?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

That is all I really need. The ability to either include line breaks into a single string or have it allow multiple additions to a label or textbox.. or something..

This is to be read only text though.. no changes..

can anyone help?


RemiD(Posted 2014) [#2]
You can search the code archives, there are already several examples to do automatic line break.

If i understand correctly, what you want to do is more like manual line break with a symbol or a word

To do this, what i would do :
Get the text from an external file or from inside your code and store it in a string variable

Then, analyze the string and extract words and store each word in an array (for this you can use Mid() and Len())
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Mid
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Len

Then,
create a new line
While the current word is inferior or equal to the count of words
analyze the stored word
if the word correspond to the symbol you use for a line break
store the current line
create a new line
else
add this word to the string of the current line
Wend

Then,
you will be able to use SetFont() and Color() and Text() to draw each line as you want

Try that,
Good luck !


Andy_A(Posted 2014) [#3]
Like RemiD said there's a lot of stuff in the archives.

Here's a couple of functions that I use for this kind of stuff. You may be able to use them.




DRH(Posted 2014) [#4]
Well I had written a word wrap in blitz 3d which is what I was using before I decided that I loved the menu system in plus, ha ha, and I used [ as the line break. whenever the program encountered [ it would break the line and ] was " so I could in effect use a blitz program to act as my file converter. I used that to save the strings with the variables that the descriptions would need for the engine to use them.


I will look through the archives but I had another thought. Rather than bothering with using one giant string that is a combination of others, why not just use multiple labels and have the program figure out how tall the label is. then link the labels to a slider?

So.. I'm going to hunt down a cheap and easy solution to the question of finding out how tall a text is on the screen. so that even if the screen size is altered the labels will stay separated by at least a single line. and whenever they are updated they will shift to the new location and still all be seperate.

Anyways, that is what I am looking for now, a way to judge the vertical size of a text or label after word wrap.


Matty(Posted 2014) [#5]
Why use labels? why not use a textarea?


DRH(Posted 2014) [#6]
Hmm.. well some of this is new to me, but.. Texture makes me think of an image.. lol..

I guess I could some how make a buffer, draw the text, then scan for the size of it vertically, heh.....

What do you mean? I'm new with plus, only having experience in blitz3d so.... advice?


Matty(Posted 2014) [#7]
No...not a texture....a textarea. Blitz plus gui control...look it up.


Gauge(Posted 2014) [#8]
use chr$(10) to add a line feed, anywhere you put chr$(10) in your textarea it will give you a blank line...twice for doublespacing.