Page 1 of 1
Problem with Tasty Text's setSub
Posted: Fri Dec 02, 2016 12:06 am
by megalukes
I'm using
Tasty Text to create dialog windows, but I'm having some trouble with the :setSub function. Have a look:
- text issue.gif (61.86 KiB) Viewed 3469 times
Everytime setSub goes to a new line, it draws its firt character twice (it doesn't happen in the last line for some reason). How do I solve this?
Re: Problem with Tasty Text's setSub
Posted: Fri Dec 02, 2016 2:35 am
by Positive07
That is a problem with tasty text, it counts the newline (\n) character when doing the substring but not when rendering. It should ignore it as a character. That is if a newline character is found it should go to the next (not newline) character.
But I haven't used nor developed the library so I can't really help you. I think you should post an issue to their issue tracker.
Re: Problem with Tasty Text's setSub
Posted: Wed Feb 22, 2017 7:10 pm
by PerdeT
I'm facing the same problem... I got rid of the flashing character by changing the last line of function TastyText:setSub to this:
self.first,self.last = first-1,last
But it's a dirty "solution" and creates a whole lot of problems. I think I'll try to find how to at least locate the bug Positive07 mentioned.
Re: Problem with Tasty Text's setSub
Posted: Wed Feb 22, 2017 11:51 pm
by Positive07
The problem is the _parseString function, that thing strips new line characters, trailing whitespace, tags and whatnot, when you setSub you are actually setting it to the original string, and then when it calculates the length of each chunk it doesn't add the characters it deleted (new lines, whitespace, tags).
Basically it sets self.first and self.last based on the parsed string. To parse it strips newlines and creates an array with all the chunks that make up the text (images, each line of text and everything else) and calculates the length of each chunk (but chunks don't have newline or trailing whitespaces anymore). When rendering it adds the length of the chunk until self.first is inside of the current chunk and renders it (self.first takes into consideration newlines and trailing whitespace while chunk.length does not), then it keeps drawing until chunk.length added up to be more than self.last (self.last takes into consideration newlines and trailing whitespace while chunk length does not)
This discrepancy between self.first and self.last taking into consideration newlines and trailing whitespace and chunk.length ignoring them is the error you are currently experiencing.
The solution would be to count newlines and trailing whitespace and subtracting it from self.first and self.last. I think that should be enough
Also note that markandgo library hasn't been updated in a year and a half so I would counted as deprecated and wouldn't use it in a new project.