Last 5 words of a field set to italic
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 6
- Joined: Sat Jun 17, 2017 5:21 pm
Last 5 words of a field set to italic
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
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
Bonjour Remi,
Try this:
set the textstyle of word -5 to -1 of field 1 to "underline"
Regards,
Thierry
Try this:
set the textstyle of word -5 to -1 of field 1 to "underline"
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Last 5 words of a field set to italic
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:

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

-
- Posts: 6
- Joined: Sat Jun 17, 2017 5:21 pm
Re: Last 5 words of a field set to italic
Thanks, Thierry!
I'd tried
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
I'd tried
Code: Select all
set the textStyle of 5 last words of field 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
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?
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?
Last edited by dunbarx on Mon Jun 19, 2017 2:55 pm, edited 1 time in total.
Re: Last 5 words of a field set to italic
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:
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
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
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
Last edited by dunbarx on Mon Jun 19, 2017 4:02 pm, edited 2 times in total.
Re: Last 5 words of a field set to italic
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)

*edit - loved the trip down nostalgia lane CraigObjects (or Types): card,stack,group,field,button,graphic,scrollbar,player,image


-
- Posts: 6
- Joined: Sat Jun 17, 2017 5:21 pm
Re: Last 5 words of a field set to italic
Hi.
Thank you dunbarx, for this very inspiring post.
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!)
Thank you dunbarx, for this very inspiring post.
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: 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.
And I was wrong looking for such a use of variables.dunbarx wrote: I am intrigued: what use would variables have if they did have styles of any kind? What are you trying to do?
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
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
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