Last 5 words of a field set to italic

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RevigBreizh
Posts: 6
Joined: Sat Jun 17, 2017 5:21 pm

Last 5 words of a field set to italic

Post by RevigBreizh » Mon Jun 19, 2017 7:47 am

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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Last 5 words of a field set to italic

Post by Thierry » Mon Jun 19, 2017 8:48 am

Bonjour Remi,

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.
!

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Last 5 words of a field set to italic

Post by bogs » Mon Jun 19, 2017 9:15 am

Thierry, glad you posted, I actually initially had it backwards :roll:

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
Image

RevigBreizh
Posts: 6
Joined: Sat Jun 17, 2017 5:21 pm

Re: Last 5 words of a field set to italic

Post by RevigBreizh » Mon Jun 19, 2017 9:32 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Last 5 words of a field set to italic

Post by dunbarx » Mon Jun 19, 2017 2:41 pm

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?
Last edited by dunbarx on Mon Jun 19, 2017 2:55 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Last 5 words of a field set to italic

Post by dunbarx » Mon Jun 19, 2017 2:53 pm

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
Last edited by dunbarx on Mon Jun 19, 2017 4:02 pm, edited 2 times in total.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Last 5 words of a field set to italic

Post by bogs » Mon Jun 19, 2017 3:04 pm

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 :D
Image

RevigBreizh
Posts: 6
Joined: Sat Jun 17, 2017 5:21 pm

Re: Last 5 words of a field set to italic

Post by RevigBreizh » Tue Jun 20, 2017 9:44 am

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!)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Last 5 words of a field set to italic

Post by dunbarx » Tue Jun 20, 2017 2:53 pm

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

Post Reply