Page 1 of 1
Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 7:47 am
by RevigBreizh
Hi,
I am looking how to use the textStyle property.
How to set the last 5 words of a field to italic?
I didn't find it into the documentation. Probably an insufficient search… Can you help me?
Thanks,
Rémi
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 8:48 am
by Thierry
Bonjour Remi,
Try this:
set the textstyle of word -5 to -1 of field 1 to "underline"
Regards,
Thierry
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 9:15 am
by bogs
Thierry, glad you posted, I actually initially had it backwards
Was trying to work it out for myself while you posted, the commented section is what I started with, pasted into a card with a field:
Code: Select all
on mouseUp
/* false start
// set the itemDelimiter to " "
// set the textStyle["italic"] of item -1 to -5 of field "Field" to false
*/
// corrected using Thierry's solution to change from normal to italic when card is clicked on ...
if the textStyle["italic"] of word -5 to -1 of field "Field" is "true" then
set the textstyle of word -5 to -1 of field "Field" to ""
else
set the textstyle of word -5 to -1 of field "Field" to "italic"
end if
end mouseUp
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 9:32 am
by RevigBreizh
Thanks, Thierry!
I'd tried
Code: Select all
set the textStyle of 5 last words of field 1
but this chunck was no recognized. I didn't know the syntax: word -5 to -1.
What about the second question: is it possible to manage the styles "inside" a variable? How to attach styles to parts of text in a variable?
Regards,
Rémi
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 2:41 pm
by dunbarx
Hi.
Variables are simply raw text, that is, they have no textStyle characteristics at all. They are containers that hold data for future use. You can indeed store the htmlText of a field, say, in a variable, and the "styles" of the original source are included as tags in the raw data. But my point is that variables are only intermediates in the process of storing text; it is only when one brings back that information into the "physical" world that such things finally show their unique qualities.
I wonder if that is clear...
I am intrigued: what use would variables have if they did have styles of any kind? What are you trying to do?
Craig Newman
EDIT.
Was the ability to store the htmlText what you were really looking for?
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 2:53 pm
by dunbarx
And just for nostalgia's sake, this "word -5 to -1" stuff is all new and fancy.
Since you tried to create your own syntax, which seemed reasonable but did not compute, know that in the old days we would have written:
Code: Select all
answer word (the number of words of fld 1) - 4 to (the number of words of fld 1) of fld 1
If you can read this, you will see how LC can be twisted to your own use.
Note the "-4" in the code (as opposed to the "-5" in the newfangled way). This is just the way humans count, that is, inclusively.
Craig
Re: Last 5 words of a field set to italic
Posted: Mon Jun 19, 2017 3:04 pm
by bogs
I also don't think it would work on text in a custom property, Usually, the dictionary will tell you what objects or types commands are meant to work on, like so (from textStyle)
Objects (or Types): card,stack,group,field,button,graphic,scrollbar,player,image
*edit - loved the trip down nostalgia lane Craig

Re: Last 5 words of a field set to italic
Posted: Tue Jun 20, 2017 9:44 am
by RevigBreizh
Hi.
Thank you
dunbarx, for this very inspiring post.
dunbarx wrote:
Variables are simply raw text, that is, they have no textStyle characteristics at all. They are containers that hold data for future use. You can indeed store the htmlText of a field, say, in a variable, and the "styles" of the original source are included as tags in the raw data. But my point is that variables are only intermediates in the process of storing text; it is only when one brings back that information into the "physical" world that such things finally show their unique qualities.
You're perfectly right. I was using variables as containers, like in many other programming languages, without figuring out that with LiveCode, the common containers are fields. It is a change of perspective I have to get used to.
dunbarx wrote:
I am intrigued: what use would variables have if they did have styles of any kind? What are you trying to do?
And I was wrong looking for such a use of variables.
Thanks again!
(I'm surprised. I used to create stacks with HyperCard, a long time ago… It was fun, it was efficient, it was exciting. I should retrieve my old habits!)
Re: Last 5 words of a field set to italic
Posted: Tue Jun 20, 2017 2:53 pm
by dunbarx
Welcome.
Not to put too fine a point on it, but variables are indeed containers, along with fields, buttons and others. They were in HC as well.
And if you liked HC, you will love LC.
Craig