Page 1 of 2

The selectedLine...

Posted: Fri Feb 05, 2021 12:09 am
by bogs
I'm sure everyone else but me knows the answer to this heh, so I hope someone will let me in on it.

I'm looking for the last word in a field in the 'on textChanged' handler. Thinking this *should* be fairly straight forward, I used the following -

Code: Select all

on textChanged
   put word -1 of the selectedLine into myLine
   answer myLine
end textChanged
I am expecting to see "do" in the answer dialog, however, I am sorely disappointed! <shocking, I know> :twisted:

So I turn to the message box, and spelling it out, I get the answer I think I should have. I used the same format returned by the selectedLine, how come the selectedLine doesn't give me the same result ? (See picture below).
aPic_selectedLine.png
When this sucker hits 88 mph, your really going to see some shit....

Re: The selectedLine...

Posted: Fri Feb 05, 2021 12:23 am
by SparkOut
well... the selectedLine produces a string such as "line 1 of field 1" so... the last word of the literal string "line 1 of field 1" is 1.

Code: Select all

the last word of the value of the selectedLine 
will evaluate the selectedLine to return the actual word needed. Or "the text of the selectedLine" might be better.

I'm not sure if that forced evaluation is necessary when using all other chunk definitions.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 10:23 am
by bogs
Yes, that is exactly the string the selected line produces, just as if you were typing exactly that into the script (as I did), it should work I would think.

However, I had tried many other variations like the one you just stated, and they didn't work either.
aPic_selectedLineValue.png
Can I get some value for my change ?
By the way, I also tested this in the current IDE, I'm thinking 'bug' at this point heh.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 11:10 am
by AndyP
Try

Code: Select all

put word -1 of the text of the selectedLine into myLine
the text being what you are missing

Re: The selectedLine...

Posted: Fri Feb 05, 2021 11:52 am
by bogs
Thanks Andy, that does actually work (and it helped me uncover a different kind of bug involving the script editor ~! **Bonus gravy!!)

The question becomes *why* do you need the qualifier/descriptor?

In other words, if you were writing this out with a fixed line already in mind, would you not write it something like -

Code: Select all

put word -1 of line 1 of field 1 into myWord
The selectedLine gives you the insertion point exactly like that, "line x of field y". Why doesn't the statement work using the selectedLine? (I know, this is above our pay grade, but I think the question is legitimate).

**Bonus gravy!! -
1. set up a field on a stack, type some words into it.
2. in the script editor, put the following code -

Code: Select all

put word -1 of the text of the selectedLine into myLine
3. set a breakpoint at that line
4. in the field, hit the space bar
5. the selectedLine becomes the line in the editor, and returns the last word of that line :twisted:
aPic_selectedLineValueSE.png
Ummmmmmmm.......
*Edit - actually, a trip through the qdb showed me this is a long standing problem :(

https://quality.livecode.com/show_bug.cgi?id=6425
https://quality.livecode.com/show_bug.cgi?id=6988
https://quality.livecode.com/show_bug.cgi?id=12640
https://quality.livecode.com/show_bug.cgi?id=21219

Re: The selectedLine...

Posted: Fri Feb 05, 2021 1:53 pm
by SparkOut
bogs wrote:
Fri Feb 05, 2021 11:52 am
would you not write it something like -

Code: Select all

put word -1 of line 1 of field 1 into myWord
The selectedLine gives you the insertion point exactly like that, "line x of field y". Why doesn't the statement work using the selectedLine? (I know, this is above our pay grade, but I think the question is legitimate).
What's being interpreted is not

Code: Select all

put word -1 of line 1 of field 1 into myWord
but instead

Code: Select all

put word -1 of "line 1 of field 1" into myWord
which is perfectly correct if the selectedLine is meant to resolve as a string literal. I'm not sure it should.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 2:31 pm
by bogs
SparkOut wrote:
Fri Feb 05, 2021 1:53 pm
...which is perfectly correct if the selectedLine is meant to resolve as a string literal. I'm not sure it should.
Yes, reading through those BRs made that clear, at the very least the dictionary should be updated to reflect it as mentioned by Trevor in one of those BRs.

There isn't any easy way (that I know of) to tell that you are getting a string literal back from the function, and the dictionary makes it look as though you are not with how the return example is formatted, i.e. -
Image

By the way, regarding your earlier post on the value, I finally figured out how that needs to be done, at least here, I had to split it into 2 lines heh.

Code: Select all

   put the value of the selectedLine into myLIne
   answer word -1 of myLIne
I didn't test up to the newest IDE on that one, though, so it may have changed.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 2:35 pm
by SparkOut
I do think (and did say as much, in the earlier post) that "the text of" is probably better. But that shouldn't affect the scripting.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 2:47 pm
by bogs
No, it doesn't, I'm just trying to improve my own understanding of how this language works, things I expected by this point to be easy wind up giving me competency complexes.

Every time I *think* I know how something *should* work, it never does seem to work out that way. It is very depressing to me.

Re: The selectedLine...

Posted: Fri Feb 05, 2021 7:32 pm
by bogs
Something else I really wonder about, why doesn't the script ...

Code: Select all

put the last word of this line into myWord
work in a field 'on textChanged' handler?

The above assumes the field has focus and a blinking cursor in it, I am not talking about some random line in some random field hee hee :twisted:

Re: The selectedLine...

Posted: Fri Feb 05, 2021 9:09 pm
by dunbarx
Bogs.

The keyword "this" only applies to stacks and cards. Not chunks.

Craig

Re: The selectedLine...

Posted: Fri Feb 05, 2021 9:15 pm
by dunbarx
Bogs.

I think what you are thinking is something like this:

Code: Select all

on textChanged
   put the last word of line (word 2 of the selectedLine) of me into fld 2
end textChanged
You do need a field 2.

Craig

Re: The selectedLine...

Posted: Fri Feb 05, 2021 9:22 pm
by bogs
I did already hit that bit of code in testing, which probably isn't surprising heh. Variations on it are hit and miss though, just as they are with 'the text of' and 'the value of' :|

Honestly, for how easy something *should* be, it doesn't really seem to be, at least not to me.

I'll be exploring offsets next, i'm only 2 days in at this point <sigh>

Re: The selectedLine...

Posted: Fri Feb 05, 2021 11:30 pm
by bogs
This is where this topic was all heading towards, more or less. I could have cheated and just went through the code of the various SE's, but what the heck kinda fun is that ? :twisted:

Image

Re: The selectedLine...

Posted: Sat Feb 06, 2021 2:49 am
by dunbarx
Variations on it are hit and miss though,
I think I sort of know what you mean, with:

Code: Select all

 put the last word of line (word 2 of the selectedLine) of me into fld 2
The "last word of" is straightForward, but then the phrase "...line (word 2 of the selectedLine) of me..." likely throws new users due to the string "keyword/chunk/function/keyword", which has to be oddly mentally parsed to create it as well as read it.

It encapsulates the beauty and peculiarity of this sort of language I suppose. I love it. Don't ask me about "do". :wink:

Craig