Scrollable text with varying lengths

fmakawafmakawa Member Posts: 565

I asked this a while back and never got a response. Anyone with an idea? I wish to add pages of world information. How do I create a display text actor that scrolls so that even if text doesn't fit within the actor I can scroll through it so I can read all of it? The text itself is never uniform in length. At times it 5 lines, at times 20 depending on the information I am giving.

Comments

  • ArmellineArmelline Member, PRO Posts: 5,354

    I don't think you can do it dynamically - you need to know how many lines you're displaying each time. If you work that out and stick the number of lines in a table or something this becomes a lot easier.

  • fmakawafmakawa Member Posts: 565

    i suppose I can work that out. Lot more work but we don't shy away from that! But even then, how would I manage the scrolling? Make it recognise the line of each entry and stop when it does get there?

  • ArmellineArmelline Member, PRO Posts: 5,354

    You'd have to go by actor size, probably. Work out how big an actor needs to be to show x lines.

  • fmakawafmakawa Member Posts: 565

    But then I fall into the problem of having an actor that becomes too big for the screen. Rather what I need to do is have an actor of specific size that you could scroll the text of which ever length till its done.

    @Armelline said:
    You'd have to go by actor size, probably. Work out how big an actor needs to be to show x lines.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    When you set up scrolling text, you usually have a "window" actor that provides the border for the text area and then a "text" actor that actually displays the text but sits under/behind the window actor and moves up and down to simulate scrolling. So in that case, you'd resize the text actor according to the number of lines, while the window actor would stay the same size.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • fmakawafmakawa Member Posts: 565

    @tatiang @Armelline, curious, is the count function or any of its ilk in GS capable of counting the number of words in a particular cell within a table? I ask because I was thinking: instead of proofing every single piece of text to see its fit I could create an equation that guesstimates the length and then using that as an attribute for the lines required. ie my actor is x pixels wide and on average fits 8 words per line. so equation would be something like this:

    = ( COUNTORSOMETHINGLIKEIT(Randomtexttable, 2,10))/8

    So having counted the number of words in that cell it would divide that by 8 (the number of words per line) and coming to a value that is the number of lines I would need.

    Can that be done or am I barking up the wrong tree?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I thought of that, too. It's not exact, of course, but it might be a close enough estimate, especially if you round up.

    There's no built-in way to count words but you can do it using a loop. Cycle through the characters in a table cell using textSubStr() and each time you reach a space, add one to the word count.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • vikingviking Member, PRO Posts: 322

    I have a text window in my game that is dynamically adjusting it's size based on how many characters I have in each cell.

    It looks like this: self.Size.Height = (textLength(tableCellValue(game.tableName,1,1))*1.2)

    I added the *1.2 just to make the text box a bit bigger to give the text some room to breathe.

    Then I display the text from that table cell value in the box and it works great. Hope that helps...

  • ArmellineArmelline Member, PRO Posts: 5,354
    edited March 2016

    @tatiang said:
    There's no built-in way to count words but you can do it using a loop. Cycle through the characters in a table cell using textSubStr() and each time you reach a space, add one to the word count.

    An easier way that avoids loops would be to compare the length of the original string with the length of a string that has used textReplaceAll to remove the spaces.

    Adjusting the actor's height is going to cause problems for long pieces of text, though.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Armelline said:
    An easier way that avoids loops would be to compare the length of the original string with the length of a string that has used textReplaceAll to remove the spaces.

    Ooh, smart!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,354

    Not really sure what you're going for, but perhaps something like this might be helpful.

  • fmakawafmakawa Member Posts: 565

    What is the file meant to do? Perhaps mine is buggy but in preview mode its not showing anything beyond a thin grey bar.

    @Armelline said:
    Not really sure what you're going for, but perhaps something like this might be helpful.

  • ArmellineArmelline Member, PRO Posts: 5,354
    edited March 2016

    Should look like this. Must use something not available on PC. Actor resizes depending on the amount of text.

  • fmakawafmakawa Member Posts: 565

    Thanks! Its fantastic. I will figure out what's wrong with mine. Perhaps it a PC thing but I'm sure there is a work around that I can come up with.

    @Armelline said:
    Should look like this. Must use something not available on PC. Actor resizes depending on the amount of text.

  • fmakawafmakawa Member Posts: 565

    @Armelline I've been working with this demo and I finally managed to work out the issue with a grey line. However when I use for my project I seem to have a similar problem but different cause. And I was wondering perhaps it might have to do with the change from iPhone 5 that youre using to the iPad res I am using. So, what is the pursoe of the of the change self.size.height string which ends ---> +1)/4.2)*34

    I've tinkered a little with value of 34 but I dont want to mess up your good work because of my lack of understanding of the functions of each value.

  • ArmellineArmelline Member, PRO Posts: 5,354
    edited May 2016

    The 34 is the line height - increase it for more space between lines (as in, if you use bigger text font size). The 4.2 was the average characters per word, if I remember right.

    These values no longer work with the default text in 1.25, though. They'll need adjusting for sure.

  • fmakawafmakawa Member Posts: 565

    @and the 1? thanks, I got it working fine now!

  • ArmellineArmelline Member, PRO Posts: 5,354

    @fmakawa said:
    @and the 1? thanks, I got it working fine now!

    I honestly can't remember. I'll take a look later!

Sign In or Register to comment.