Multi-line text boxes? [SOLVED]

tamercloud

  • Posts: 74
Hi guys,

I am having the hardest time with creating text boxes that automatically set words to new lines. I've tried all of the text boxes on Forge and either can't get them working, or they are too outdated.

What I need to do is create an instructions page with text that differs depending on what option the player chose, so I have no idea if it is better to attach text behavior to an invisible actor or the scene itself.

« Last Edit: July 24, 2013, 03:40:23 pm by tamercloud »

ipe 369

  • Posts: 1001
Make it yourself, you have to split the string into words, then check if the word fits on the line, if not, make a new line. use the 'get width of __ using font __' block in the drawing section.
Good luck, be a great opportunity to learn how to use the design blocks.

If you're really struggling (and i mean struggling, not just being lazy) i can give you some help, i have had to do this before and it proved quite taxing:)

tamercloud

  • Posts: 74
Make it yourself, you have to split the string into words, then check if the word fits on the line, if not, make a new line. use the 'get width of __ using font __' block in the drawing section.
Good luck, be a great opportunity to learn how to use the design blocks.

If you're really struggling (and i mean struggling, not just being lazy) i can give you some help, i have had to do this before and it proved quite taxing:)

I'm relatively new to this program, but this is what I have so far. All it seems to do is give me 1 second of lag and no text to show for it.

« Last Edit: July 18, 2013, 12:00:21 pm by tamercloud »

ipe 369

  • Posts: 1001
you have blank spaces.

tamercloud

  • Posts: 74
you have blank spaces.
No worries about that. I had code in a different block that allows for blank spaces. It's exactly how it looked when I downloaded it from forge.

rob1221

  • *
  • Posts: 9473
Anything under the drawing wrapper is run many times per second, so you don't want to loop through lists more than you have to.  Use booleans to control your code and only set up the list when your text changes.  You may also need to empty line list each time, but I'm not sure.

froz

  • Posts: 250
Make it yourself, you have to split the string into words, then check if the word fits on the line, if not, make a new line. use the 'get width of __ using font __' block in the drawing section.
Good luck, be a great opportunity to learn how to use the design blocks.

If you're really struggling (and i mean struggling, not just being lazy) i can give you some help, i have had to do this before and it proved quite taxing:)

I'm relatively new to this program, but this is what I have so far. All it seems to do is give me 1 second of lag and no text to show for it.

There is no block to actually draw text in the code you showed us. The mechanic to prepare the text looks ok, though you should only calculate it once when needed, not every frame (what rob said) and it is good to always create new list by "set listattribute to [create new list]". Otherwise it sometimes doesn't work like expected, at least for me.

tamercloud

  • Posts: 74
Make it yourself, you have to split the string into words, then check if the word fits on the line, if not, make a new line. use the 'get width of __ using font __' block in the drawing section.
Good luck, be a great opportunity to learn how to use the design blocks.

If you're really struggling (and i mean struggling, not just being lazy) i can give you some help, i have had to do this before and it proved quite taxing:)

I'm relatively new to this program, but this is what I have so far. All it seems to do is give me 1 second of lag and no text to show for it.

There is no block to actually draw text in the code you showed us. The mechanic to prepare the text looks ok, though you should only calculate it once when needed, not every frame (what rob said) and it is good to always create new list by "set listattribute to [create new list]". Otherwise it sometimes doesn't work like expected, at least for me.
I'm very new with this program so understanding this is quite difficult, but here is what I have now. I'm assuming that you want me to create a new list from Word List, but I have no idea what to do with it or how to reference a new list. I don't know how to check if the whole list has been run through, so "set text drawn to true" makes it not work. Without the attribute I can draw the text, but it is all on one line and has "undefined" at the start of it for some reason.

froz

  • Posts: 250
You should draw each line separately (each text attribute, not the hole list attribute) and move pen some pixels lower every line.

And the "create new list" is a code block. Check this article about lists:

http://www.stencyl.com/help/viewArticle/73

tamercloud

  • Posts: 74
You should draw each line separately (each text attribute, not the hole list attribute) and move pen some pixels lower every line.

And the "create new list" is a code block. Check this article about lists:

http://www.stencyl.com/help/viewArticle/73
I managed to draw all of the text by making a list! However, there are some problems.

First: I still have the "Undefined" thing showing up at the start of my text.

Second: On my final line when it reaches the end, it keeps drawing from the beginning for the remainder of that last line.

Third: I don't know how to check if a the list has been completed, hence where I put "finished?"

tamercloud

  • Posts: 74
Also, I figured out exiting the loop will delete all of my drawn text, but the problem is that all the formatting goes on from within the loop.

« Last Edit: July 23, 2013, 09:50:28 am by tamercloud »

froz

  • Posts: 250
You are still not using "create new list" block. Did you read the article about tables I linked in my last post?

As for other problems - there are some fundamental mistakes you make. For example, you need to understand how drawing works.

Everything in "when drawing" happens 60 times per second (every frame). If you need text to be drawn, it needs to be drawn 60 times per second. However, calculations of the text does need to be done only once, when it is created/changed. So - you need check if the list was prepared and run the code to prepare it only if it wasn't prepared or it needs to be changed. Furthermore, you need to separate drawing from calculating, because you need to draw the text every frame.

It is good habit to always start drawing with blocks setting the drawing space (in this case switch to scene space).

You can and should use "print" blocks to check if everything is working as you expect it. Print block will "print" whatever you put inside in the console log (accessible with ~ key in the game). This can be very useful and it could answer your questions.

In general, when you start using an attribute that you don't want to be "remembered" for later frames of the game, you should start using it by (re)setting it something (like you set New Line to 0). You don't set Current Line to 0, but you should, don't count on that it will magically be back to 0 on the second frame of the game.

tamercloud

  • Posts: 74
You are still not using "create new list" block. Did you read the article about tables I linked in my last post?

As for other problems - there are some fundamental mistakes you make. For example, you need to understand how drawing works.

Everything in "when drawing" happens 60 times per second (every frame). If you need text to be drawn, it needs to be drawn 60 times per second. However, calculations of the text does need to be done only once, when it is created/changed. So - you need check if the list was prepared and run the code to prepare it only if it wasn't prepared or it needs to be changed. Furthermore, you need to separate drawing from calculating, because you need to draw the text every frame.

It is good habit to always start drawing with blocks setting the drawing space (in this case switch to scene space).

You can and should use "print" blocks to check if everything is working as you expect it. Print block will "print" whatever you put inside in the console log (accessible with ~ key in the game). This can be very useful and it could answer your questions.

In general, when you start using an attribute that you don't want to be "remembered" for later frames of the game, you should start using it by (re)setting it something (like you set New Line to 0). You don't set Current Line to 0, but you should, don't count on that it will magically be back to 0 on the second frame of the game.
I haven't used the "create new list" block because I still do not understand why or where I need it in the code. Please keep in mind that I'm a beginner with this software so I'm not familiar at all with lists referencing looping dynamic lists. It's very surprising that the text behavior downloaded from Forge was so horribly broken. So far I have three lists running in the code.

I have done some debugging and all I can tell is that the unidentified problem is coming from the line list itself, but as to why, I have no idea. Maybe it has something to do with the last couple of words not even drawing.

Anyways, this is about as far as I can take it. The drawing is very crude and not dynamic like I wanted it to be, but it is the only way I figured was possible. I also ended the loop at an arbitrary 10 number since I can't reference when the list ends.

After a debug displaying States List, something very strange is happening that can only be described as a complete mess. This is all the list should display (first stored in the Text attribute):

Help Chase cross the finish line! In order to cheer him on, you must list things that fit under the category. Once you type in an answer, hit [enter]. If the word fits, the crowd will cheer him on!  For this race, list as many items as you can in ten minutes!



froz

  • Posts: 250
Quote
I haven't used the "create new list" block because I still do not understand why or where I need it in the code. Please keep in mind that I'm a beginner with this software so I'm not familiar at all with lists referencing looping dynamic lists. It's very surprising that the text behavior downloaded from Forge was so horribly broken. So far I have three lists running in the code.
If you want to learn, read stencylpedia. I have provided you a link to the article about lists and "create new list" block is explained there. There are tons of other useful articles in the stencylpedia.