Text Box behavior (updated 10th March 2012!)

Sunflower

  • Posts: 591
--- Important! ---
A beta of improved version of Text Box (to be found in "Text Box Extended Pack" on Forge) is out. Please check it, especially since it contains new features, as improved tagging system, new alignment options and spacing and it's generally tw... twen... (*succesfull roll on Will check*) twentyonepercentcooler!!1 :D
/// Important! ///

(original post begins here)
So, after hours of intense work I've finally managed to make not one and only anymore*
Text Box behavior

Here's the test of this behavior, as well as others, expanding the possibilities of the original one: [LINK]

Having this behavior attached to an actor, you can:
  • define the maximum width of text
  • set the number of lines shown at once, as well as single line height (when there are more lines, there's function which allows you to define from which line it should start drawing)
  • align it horizontally and vertically (vertical align only works when text contains less lines overall than can be shown)
  • change font in the middle of text (note that there are only open tags; when you want to return to default formatting, you just type [ default ]); if you want to make a new tag, you should use define as custom block
  • use any characters as opening and closing bracket for tags, as well as you can use any text as newline (it shouldn't contain these brackets, though)

However, you cannot set the colours for fonts. I mean, if you want to use other coloured font, you should duplicate base one and set new colour in resource. It's because drawing fonts with colour other than their own seems to take much more time to render (about 2-3 times more, apparently O.o).

Special thanks for Justin, who've managed to recover the behavior after I couldn't open it for some strange reason. Without that... well, without that I'd probably do it again, anyway, but before that I'd probably bite everyone in their ankles, so yes, that's a good thing that it was recovered.

Pack containing the behavior itself, as well as testing behavior with fonts it uses are to be found on Stencyl Forge as Text Box Pack.
Behavior itself can be found as Text Box.
I recommend checking out the pack first; behavior was placed there so that someone who already knows how to use it wouldn't have to download the whole package.

Any suggestions? ;)

*see also different behaviors from Text Box series; to be found on Forge as:
TxBx Colour

« Last Edit: March 10, 2012, 11:26:46 am by Sunflower »

niccosw

  • Posts: 91
I'm having trouble using it.

I can see the Text Box Field and change it's size, but I don't see the demo text from "Test Box". It is just a blank grey area.


Sunflower

  • Posts: 591
Well, first, have you set fonts in "Test Box" behavior? They should go like:
black, red, yellow, blue, 3x black.

If you set it so and it still appears to be invalid, then try checking console. If there's something like: "Error for when created in Test Box" or so, then I have no idea what could cause it (it happened to me once from 3 downloads), maybe it's connected with order of behaviors initialization.
Anyway, if you experience such problem, there are to ways to get around it:
 - place all blocks in "when created" block in "do after [ x ] seconds" block, where x > 0
 - place those blocks in some "when this hears [ message ]" block, and add calling this message in Text Box' "when created" block

Apparently if you don't try to call these functions immediately, everything seems fine. If not, it may work, it may not, so that's probably something with behaviors order (which we can't really control; we can try to, but it's still unsure >_<).

Please let me know if you get it to work!

« Last Edit: July 30, 2011, 06:45:17 am by Sunflower »

Darkhog

  • Posts: 1243
Sunflower, could you make version with color changing? 8ms isn't that big.

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

Sunflower

  • Posts: 591
Oh, alright, I suppose I can add it. I'll go out quite soon, so I'll probably get around to it this evening or next morning (+9 to forums time). I'll probably upload it as a separate behavior, since it'll have a bit different structure and other people might actually want to save these 5-6 ms.

Also, won't you mind if colours will be there as parts of format? So instead of defining e.g. [ red ] as ("Red Font", 0) you would define it as ("My Font", [red colour], 0), where "0" is an offset.
Such solution is easier for me to make, as it doesn't require checking if it's colorizing or shape-changing tag. ^^

Sunflower

  • Posts: 591
Done, you can search it in Forge as TxBx Colour (in behaviors section). For user, the only difference between this behavior and original one is "define as" function. Now, instead of:
define [ font ][ Y offset ] as [ tag name ]
you have:
define [ colour ][ font ][ Y offset ] as [ tag name ]

I hope you won't have problems with using these functions. ^^

Epic428

  • Posts: 1118
This seems pretty cool. I recommend posting a sample game that demos the two behaviors if possible. I don't have much time to download it and play around with it, but it would be nice to see what it can do :)
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Sunflower

  • Posts: 591
Well, here it is!
http://www.stencyl.com/game/play/5953

One thing: you should test "Text Box" first, and then "TxBx Colour". It's because apparently exporting to SWF has some bug, and font colour doesn't get cleared. It gets... well, I don't even know what it gets. O.o

It seems that I need to make a post in Bugs section... again. -. .-'

Darkhog

  • Posts: 1243
Sunflower, I think I have idea for next behavior which would be dialog behavior using either TextBox or TXBXColor behaviors. They'll will have to be changed a bit though.

First of all I'd like it to write text letter by letter and have following additional commands

{sp=xxx} - sets speed of letter-by-letter writing to xxx (actually xxx is delay between letters in ms).
{p=xx.xx} - pauses text for xx.xx seconds
{tglwri} toggles writing letter-by-letter and write-at-once on second though using {sp=0} would work as well.
also I need block to toggles autoscroll when text overfills box. It's useless in write-at-once mode, but may come in handy with letter-by-letter mode.

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

DoctorMikeReddy

  • *
  • Posts: 180
This isn't a bug in your code, but you seem to be a good person to ask, just in case I have missed something. I'm trying to play with your Text Box Test Application. The first thing was attempting to replace the manually set maintext with entries from a list. As you can see from the attachment, I just tried to create a list attribute Page Text and enter the default first message into it, then retrieve it to print. However, despite trying a range of things - empty list, add item to list assuming position 0, then trying 1, entering the text as anything in the add item, wrapping the text in an as text envelope, and so on - but I kept getting an error in the Flash Debug player. [going back now to reproduce it has gone!] Anyway, I have used debug to prove that the list has the text in it, but the first page of Test Box shows grey (no text), but the rest (untouched) works.

Just wanted to know if I am being stupid with how to use lists, or if there was something else.

Sunflower

  • Posts: 591
Alright, this is really weird.
I've been trying to do the same thing, and it indeed doesn't work. I have no idea what might be the reason, but apparently function "set something as main text" doesn't work at all when used after all this list initialization.

Unless you move all these listing things before all the definitions and such. When there's first initializing the list, and then defining fonts and setting the text to "item #0 from list as text", then everything works fine. I have no idea what might be the reason, but it seems like Stencyl bug. Really, really weird bug! O.o

Darkhog

  • Posts: 1243
Sunflower, what about my idea presented above?

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

Sunflower

  • Posts: 591
Well, I was going to add such functionality, anyway, although I'll add it when I actually go back to some text-based project I had in mind. And it'll be probably published as "Dialogue Box" or so, and Text Box will be used by it rather than Text Box will have all this built in. I just found it easier this way. ^^'

But yes, it probably won't be published anytime soon, as I'm focused on other projects right now.

DoctorMikeReddy

  • *
  • Posts: 180
I gave up using lists in the end. Just couldn't get it to work; one weird twist is that whatever I did to change the text in the list, the first sentence I set it kept coming up... :-(

Sunflower

  • Posts: 591
Could you please check the Text Box Extended Pack on Forge? It's some sort of beta containing a new version of TB, including:
  • Improved tagging system: [ font ] will change current font family to "font"; [ -tag ] or [ -gat ] will append modifiers by "tag" and "gat", respectively; [ /tag ] and [ /gat ] will remove them; [ --tag ] will remove all other modifiers and replace them with "tag"; [ // ] will remove all modifiers. You can also start using font family with modifiers directly, e.g. by calling [ font-tag ] (and then you can use only [ /tag ] to remove the modifier while still being in "font" family!)
    Remember to define all the taggings for each family. For example:
Code: [Select]
define font [Non Sarif] with offset [0] as [nonsarif]
define font [Non Sarif Bold] with offset [0] as [nonsarif-b]
define font [Non Sarif Italic] with offset [0] as [nonsarif-i]
define font [Non Sarif Double] with offset [0] as [nonsarif-b-i]
    will allow you to use both bolding and italizing with [ -b ] and [ -i ] tags for family [ nonsarif ]. If there are multiple tags, you must always include them in alphabetical order (and it's safer to not use different sized letters; I'm not sure which "text comes before/after" would treat as first in such case)!
  • New alignment options: now you can enter alignment as text (Left, Center/Middle, Right, Justify for horizontal and Top, Center/Middle, Bottom for vertical) and change the alignment for specific parts rather than whole text.
  • Spacing between letters (which you can set by changing "Spacing" attribute; note that each letter is drawn separately with Spacing different than 0, in latter case it's each word that it's drawn; so performance might be dragged down compared to unspaced text, but 4ms for basic Lorem Ipsum isn't that bad, either!), as well as some "Unspacing" attribute which reduces size of spaces between words. Don't ask, I have no idea why I've added this attribute either (not to mention that it increases space between words when it's negative)
  • Got rid of blocks for undefining fonts, because I can't really think of any typical situation when those would be needed. Also, if someone really needs them that badly, she can add them herself.

Any bugs noticed? Any suggestions for improvement?
(note that the adding text letter by letter isn't task for this behavior itself, though I might alter Textend Box a little in order to make it possible... :3)

« Last Edit: March 10, 2012, 11:48:04 am by Sunflower »