A Beginner's Question

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
rpitcairn
Posts: 17
Joined: Fri Nov 13, 2009 5:37 pm
Location: Sedona, AZ
Contact:

A Beginner's Question

Post by rpitcairn » Thu Nov 28, 2019 12:09 am

Hi, I am new to this but before I spend a lot of time studying this I thought of asking if want I intend to do is possible. My interest is in apps that can do this. Using repeat loops:
1) search text and retrieve sentences, as in a list of the various findings.
2) edit text, like if a word starts with a certain number to remove that first number and change text style to italic.

There is more but gives you an idea of what I am looking for.
Thanks for any guidance.

— Richard
Richard Pitcairn, DVM, PhD

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: A Beginner's Question

Post by FourthWorld » Thu Nov 28, 2019 1:32 am

Good to see you here, Dr. Pitcairn.

Your exercise is a good opportunity to introduce the trueWord chunk type, something new from your experience with SuperCard. Unlike the general xTalk definition of a word, trueWord uses natural language libraries to deliver an understanding of words that take semantic rules and punctuation into account, which is usually what we want for such tasks.

The example below will be good enough for fairly small runs of text (a few hundred words). If you need to work on large blocks of text I'd write this differently, using the field's styledText array. But that can be tricky to get used to when coming from a SuperCard background, so taking things one step at a time we'll make a first pass that builds on the skills you already have, introducing both trueWord and the way LC handles textStyles, with the optional textStyle array.

Like SC, LC allows you to get and set the textStyle of a chunk, but when runs are mixed that can be problematic. The textStyle array gives you control over each style attribute independently, where the array key is a style constant ("bold", "italic", "underline", etc.) and the value is true or false.

This example assumes the number you're looking for is "33", and will delete that and set the rest of the word to italic:

Code: Select all

on mouseUp
   put 33 into tNumToFind
   repeat
      put truewordOffset(tNumToFind, fld 1) into tOffset
      if tOffset = 0 then exit repeat
      delete char 1 to len(tNumToFind) of trueword tOffset of fld 1
      set the textStyle["italic"] of trueword tOffset of fld 1 to true
   end repeat
end mouseUp
I tested it on this text in a field:
11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain 11Something 22SomethingElse 33SomethingElseAgain 44AndAgain
Of course I don't know how well that fits the data you're working with (it's just a guess so probably not well at all), but at least it can get you started toward your solution.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

rpitcairn
Posts: 17
Joined: Fri Nov 13, 2009 5:37 pm
Location: Sedona, AZ
Contact:

Re: A Beginner's Question

Post by rpitcairn » Thu Nov 28, 2019 2:44 am

Richard, thank you for this thoughtful reply. Can you direct me to a user manual or a good place to reference information like this? Like if I wanted to understand trueWord, is there a place, similar to the SC help files, that gives a description of its use and parameters? I did try to access a link "docs" on the livecode web page but it took me instead to an invitation to try it out, and a video about using it. I was hoping to find some user files.

— Richard (2)
Richard Pitcairn, DVM, PhD

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6258
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: A Beginner's Question

Post by dunbarx » Thu Nov 28, 2019 3:24 am

Richard[2]

Jump in with both feet. I came to LC ten years ago directly from HC (which I still use). You will find LC dreamy.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: A Beginner's Question

Post by FourthWorld » Thu Nov 28, 2019 3:53 am

rpitcairn wrote:
Thu Nov 28, 2019 2:44 am
Richard, thank you for this thoughtful reply. Can you direct me to a user manual or a good place to reference information like this? Like if I wanted to understand trueWord, is there a place, similar to the SC help files, that gives a description of its use and parameters? I did try to access a link "docs" on the livecode web page but it took me instead to an invitation to try it out, and a video about using it. I was hoping to find some user files.
When I follow the "Docs" link I do see a Trial button if I scroll down far enough, but above that is some intro text and to the left is a menu of topics introducing the platform:
Introduction
Welcome
Introduction For Startups
Introduction For Educators
Lessons
FAQ
Language
Education Curriculum
Deployment
Components
Tooling
Core Concepts
Language Comparison
Extending LiveCode
Whats New?
Looks like a useful set of introductory info, but the resources I use most often are available right in the LiveCode IDE itself: User Guide and Dictionary.

The User Guide is too comprehensive for most to read in a single sitting, but worth a skim to see what's there and maybe read a section or two on things of interest that are different from what you know from SuperCard, such as "Custom Properties" (p148), "Programming Menus & Menu Bars" (p175), or "Using Arrays" (p409).

The LiveCode Dictionary is quite similar to the SuperTalk Language Guide, handy when you know a term and want to learn more about it.

Most of what you know from SC will work very well in LC, but don't expect complete compatibility. SC has the luxury of supporting only one platform, and when I was learning it coming from SC I ran into many things that seemed "wrong" at first, but over time I came to acknowledge that the ways they differ generally make sense for a product that covers as many platforms as LC does.

And of course you have us here in these forums to answer any questions you may have along the way.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

rpitcairn
Posts: 17
Joined: Fri Nov 13, 2009 5:37 pm
Location: Sedona, AZ
Contact:

Re: A Beginner's Question

Post by rpitcairn » Thu Nov 28, 2019 4:11 am

Thanks again. I will certainly check out these sources as I have time.
Richard Pitcairn, DVM, PhD

rpitcairn
Posts: 17
Joined: Fri Nov 13, 2009 5:37 pm
Location: Sedona, AZ
Contact:

Re: A Beginner's Question

Post by rpitcairn » Thu Nov 28, 2019 7:14 pm

on mouseup
put 2 into tNumToFind
repeat
put truewordOffset (tNumToFind, fld 1) into tOffset
_______________________________

Here is what the help window says about truewordOffset:

Returns the number of truewords between the beginning of a value and an occurrence of a specified string.

How can I understand this in this example I am playing with? It does convert word 2 to italic style. What other words could describe what is happening here?

ars. 2bell. 3 calc.

_______________________________

if tOffset = 0 then exit repeat
delete char 1 to len(tNumToFind) of trueword tOffset of fld 1

_______________________________

Same kind of question here. What does len(tNumToFind) mean? Is it saying “delete the length of what is in the variable tNumToFind? So that if there was a number like “888” it would delete all 3 characters?
_______________________________

set the textStyle["italic"] of trueword tOffset of fld 1 to true
end repeat
end mouseup
Richard Pitcairn, DVM, PhD

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6258
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: A Beginner's Question

Post by dunbarx » Fri Nov 29, 2019 5:38 pm

Richard{2}

Please place handlers in the "</>" space, found just above the editable field. It makes it much easier to read. So like:

Code: Select all

Please place handlers in the ",/>" space, found just above the editable field. It makes it much easier to read
Craig

rpitcairn
Posts: 17
Joined: Fri Nov 13, 2009 5:37 pm
Location: Sedona, AZ
Contact:

Re: A Beginner's Question

Post by rpitcairn » Fri Nov 29, 2019 6:08 pm

Did I do this right?

Code: Select all

on mouseup
put 2 into tNumToFind
repeat
put truewordOffset (tNumToFind, fld 1) into tOffset
Here is what the help window says about truewordOffset:
"Returns the number of truewords between the beginning of a value and an occurrence of a specified string."
How can I understand this in this example I am playing with? It does convert word 2 to italic style. What other words could describe what is happening here?
ars. 2bell. 3 calc.

Code: Select all

if tOffset = 0 then exit repeat
delete char 1 to len(tNumToFind) of trueword tOffset of fld 1
Same kind of question here. What does len(tNumToFind) mean? Is it saying “delete the length of what is in the variable tNumToFind? So that if there was a number like “888” it would delete all 3 characters?

Code: Select all

set the textStyle["italic"] of trueword tOffset of fld 1 to true
end repeat
end mouseup
Richard Pitcairn, DVM, PhD

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6258
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: A Beginner's Question

Post by dunbarx » Fri Nov 29, 2019 6:45 pm

Perfect. :wink:

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”