Page 1 of 1
Where am I going wrong?
Posted: Mon Mar 20, 2017 6:57 pm
by user#606
I am experimenting with a social chat module and simple though it should be, I am stumped.
The image shows the experimental set up for the various stages BUT, only post formatting to Main Feed is the problem.
A new post is made and added to Post Store as an unwrapped line, for easy addressing/manipulation.
Each line of the Posts Store is truncated after 170 characters, so it fits in less than 5 lines of the Main feed.
So I can get a single empty 5th line, I want to put the start of the subsequent line of Posts Store on the line below the 5th. As you see, I am working in modules of 5. 4 of text, 1 blank and so on.
The code should put the start of each truncated post on lines 6, 11,16,21..... But it starts 5 lines after the end of the text. Some text is less than 4 lines, so the module in Main Feed is not a multiple of 5 and I have 5 spaces, not on at the 5th module line.
The module of 5 is crucial to other functions.
Code: Select all
on mouseUp
set the lineDelimiter to return
put empty into field "Main feed"
put empty into counter
put 1 into MFcounter
repeat 10 times
put counter + 1 into counter
put char 1 to 170 of line counter of field "Posts store" into temp
put temp into line MFCounter of field "Main feed"
# answer counter, MFCounter
put counter * 5 into MFCounter
end repeat
Re: Where am I going wrong?
Posted: Mon Mar 20, 2017 9:45 pm
by monki
So "Posts store" is a field of lines, each of which you want to truncate into another field? Unless the lines are being hard wrapped somewhere I'm not seeing, you don't need the "* 5" part. While the lines are visually wrapped in the "Main Feed" field, I don't see that they are actually hard wrapped--the 170 characters aren't being wrapped by inserted "carriage returns". So LiveCode doesn't see them as taking up 5 lines, they are still just 1 line each.
So, if I'm understanding the problem, you don't need MFcounter, just something like:
Code: Select all
put empty into field "Main feed"
repeat with tLineNum = 1 to 10
put char 1 to 170 of line tLineNum of field "Posts store" into tPostSummary
put tPostSummary & cr after field "Main feed"
end repeat
and simplify the function by getting rid of the temp variable...
Code: Select all
put empty into field "Main feed"
repeat with tLineNum = 1 to 10
put (char 1 to 170 of line tLineNum of field "Posts store") & cr after field "Main feed"
end repeat
Re: Where am I going wrong?
Posted: Tue Mar 21, 2017 6:09 pm
by user#606
Hi Monki,
I do appreciate your suggestion, but that is actually not the problem. The refined code was interesting though, the 'After' might be useful.
As I explained, the modular aspect, mentioned further down, is the key to the presentation of the data in the Main feed field.
First, the truncated text might only be a word or two long, or paragraphs long in the post, but must only show as 4 lines that can contain text and one blank line, so everything in the main feed shows in 5 lines per post. No more or less. This is so the full post can be recovered from Post store and displayed elsewhere, when being replied to. The app can work out from any of the 5 lines in a module which full post it refers to.
As shown in my first post, the arbitrary string of 170 characters, if there are more than 170 in this app, will always display within the first 4 lines of each module of 5 (the 5th always being blank).
Because Main feed field is wrapped text, (Post store is unwrapped) if I attempt to read, say line 2, I end up with something starting several lines lower and for the full 170 characters or less, if there were less. This was unexpected and I need to look deeper into the issue.
Re: Where am I going wrong?
Posted: Tue Mar 21, 2017 9:01 pm
by monki
user#606 wrote:Hi Monki,
As shown in my first post, the arbitrary string of 170 characters, if there are more than 170 in this app, will always display within the first 4 lines of each module of 5 (the 5th always being blank).
Because Main feed field is wrapped text, (Post store is unwrapped) if I attempt to read, say line 2, I end up with something starting several lines lower and for the full 170 characters or less, if there were less. This was unexpected and I need to look deeper into the issue.
I guess what I'm trying to get at is the meaning of wrapped and unwrapped. Without changing it, lines are denoted by returns, ASCII 10, the documentation says. So, setting the lineDelimiter to return isn't needed unless you've changed it earlier in this script. Only the returns count as line markers. How the field is set in properties doesn't effect this. A string of 5 characters with only a single return at the end of the line is 1 line. A string of 5000 characters with only a single return at the end is also 1 line. So unless you are inserting 4 returns into the characters you're taking from "Post store" to break them into 5 lines, they'll only be a single line. Regardless of how many characters long the line is, or whether the field is set to wrap text.
So how are you wrapping the text for "Main feed"?
Re: Where am I going wrong?
Posted: Tue Mar 21, 2017 9:45 pm
by user#606
Hi Monki,
Actually I am now using the unwanted effects of how Main feed is formatted, to my advantage.
Instead of neat 5 line blocks or modules in Main feed, they can be up to the arbitrary 170 characters long or less.
Where I was going wrong, apart from seeking a neat appearance, was the wrapped text in Main feed still knows which line it came from. Effectively, this was all I needed to identify where the piece of text came from
As we both knew, a 'Don't wrap' line is a single line of text, regardless of how many characters are in it.
A wrapped line will wrap automatically and although that piece of text can be displayed as on one line or many, when you Clickline anywhere in those lines, you still get the same line number as though it was a 'don't wrap' line.
Problem solved. Thanks for putting a different spin on things with your answers. It jolted my logic out of the rut it was in.