Page 1 of 2

I just can't do it

Posted: Mon Apr 04, 2016 8:49 pm
by dunbarx
Back in the beginners area again...

I made a locked field containing a few short words with this in its script:

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
  -- put "x" after it --FAILS
   do "put" &&  it && "into" && tChunk
end mouseUp
Works fine, the "do" construction building from the contents of "it" nicely. But the "put x" line to modify the variable "it" throws an error. All I want to do is append an "x". How do it know?

Craig Newman

Re: I just can't do it

Posted: Mon Apr 04, 2016 9:11 pm
by FourthWorld
That should work without the "do", no?

Re: I just can't do it

Posted: Mon Apr 04, 2016 9:21 pm
by dunbarx
Richard.

You mean like this?

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
   put it & "x" into tChunk
end mouseUp
No.

Thought this does:

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
   put it && "x" into the clickChunk
end mouseUp
Not sure why. I was just wondering about why the appending of a character breaks the handler from the first post.

Craig

Re: I just can't do it

Posted: Mon Apr 04, 2016 9:27 pm
by FourthWorld
What happens if you put parens around it, e.g.:
put (it & "x") into tChunk

Re: I just can't do it

Posted: Mon Apr 04, 2016 10:08 pm
by dunbarx
Like this?

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
  put (it & "x") into tChunk
end mouseUp
Nope.

My point was that the use of "tChunk", as opposed to the (admittedly simpler and more straightforward "clickChunk") requires a "do" construction. This begs the issue why I cannot append a character. Just wondering why.

I checked HC. It also will not work.

Craig

Re: I just can't do it

Posted: Tue Apr 05, 2016 7:59 pm
by jacque
This works fine for me:

Code: Select all

on mouseUp
  put the clickChunk into tChunk
  put the clickText into tText
  ask "Change?" with tText
  put "x" after it 
end mouseUp
I put "This is a test" into the locked field. I clicked on the word "test". When the dialog appeared, I changed the text to "testy" and hit OK. The handler completed with "testyx" in the variable "it".

What are your steps in the dialog exactly?

Re: I just can't do it

Posted: Tue Apr 05, 2016 9:02 pm
by jmburnod
Hi Craig,
I tested your script and I've got an error in last line two times.
I rewrite last line char by char and it works fine
I compare the two last lines and didn't found something different
I tested one more your script (copied from your first post) and it works
I can believe my eyes :shock:

Re: I just can't do it

Posted: Tue Apr 05, 2016 10:51 pm
by dunbarx
@Jacque.

You never put the string back into "tChunk", that is, back into the field itself. There is no issue appending to the variable, nor even putting it back into the clickChunk (back into the field).

@Jen-Marc.

Huh? I have rewritten several variants of this silly thing and never had one work, neither whether the wrong one will or the right one will not, or the other way around. Can you post one that does indeed work?

Craig

EDIT.

Maybe I was not clear. I want to click on a word in a field, change it, and have the handler reload that new string back into the clickChunk. I can do this two ways, as per the earlier posts. But I cannot do it with the "do" construction if I append a char before I reload the new string. The question is why? Why does appending a char break the "do" process, which works fine if I do not append?

Re: I just can't do it

Posted: Tue Apr 05, 2016 11:05 pm
by jacque
I assumed the line you marked as "FAILS" was the one causing problems, but II'm not clear on what you're trying to do. It works fine to add "put it into tChunk" at the end of my example. But that doesn't make any sense. TChunk is chunk reference, but by the time the handler finishes, "it" contains literal text. Do you want to replace a chunk reference with the user text? Seems to work okay.

What's the goal, and what fails?

Here's my revised version but I get the feeling it isn't what you're trying to do:

Code: Select all

on mouseUp
  put the clickChunk into tChunk
  put the clickText into tText
  ask "Change?" with tText
  put "x" after it 
  put it into tChunk
end mouseUp
And this one works okay too:

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
  put (it & "x") into tChunk
end mouseUp

Re: I just can't do it

Posted: Tue Apr 05, 2016 11:47 pm
by dunbarx
Jacque.

I want to put a modified string back into the chunk in a field I took one from. So if I have "My dog has fleas", and I click on "dog", I want to put "dogx" right back into that (dog) spot.

I load the clickText into "it". I can do this easily as:

Code: Select all

put it && "x" into the clickChunk
and I can, if I do NOT append that "x":

Code: Select all

do "put" &&  it && "into" && tChunk
where tChunk contains the clickChunk string.

But if I try to append the "x" in the above snippet:

Code: Select all

put "x" after it
   do "put" &&  it && "into" && tChunk --same line, but with appended "it"
It fails. I wonder why, is all.

Craig

Re: I just can't do it

Posted: Wed Apr 06, 2016 1:08 am
by mwieder
Craig-

"it" is an ephemeral variable. By the time you have "put x after it" you have changed not only the contents of "it", but also the existence of "it".
Essentially, you are wiping out the engine's memory of the "it" variable by putting something into "it".
This is a weird concept, and I use the "it" variable as little as possible (immediately after something sets it) because of this.
Instead try

Code: Select all

ask "Change" with tText
put it & "x" into tVar
do "put tVar into tChunk"

Re: I just can't do it

Posted: Wed Apr 06, 2016 3:07 am
by dunbarx
Mark.

I do not understand.

I know "it" can change unexpectedly because it is the target of a number of other standard actions. But besides that, it does not change on its own, it is just a variable, after all. In my handler, "it" contains the new appended string and endures intact. Why would it not? How could it not?

But that is not what I am on about right now. I am at another computer, and the original "do" construction of the first post now works. I must tell Jean-Marc that he is not crazy.

I will try again tomorrow at my original machine, and see if it cured itself of the problem. Watch this space. If it idid, I will believe in ghosts.

Craig

Re: I just can't do it

Posted: Wed Apr 06, 2016 9:19 am
by jmburnod
@Craig
I must tell Jean-Marc that he is not crazy
After 40 years working in psychatry department, I'am so happy with this diagnostic :D

@ Jaqueline
Here is the stack i used (LC 7.06, OS X 10.10.3)

Best regards
Jean-Marc

Re: I just can't do it

Posted: Wed Apr 06, 2016 1:49 pm
by dunbarx
Well, back at my office computer, an iMac, OS10.9.5, LC v6.7.9, the following handler throws an error at the last line.

Code: Select all

on mouseUp
   put the clickChunk into tChunk
   put the clickText into tText
   ask "Change?" with tText
   put "x" after it
   do "put" &&  it && "into" && tChunk
end mouseUp
In that last line, "it" contains a simple string with the appended "x", as opposed to a simple string derived from the user entry of chars from the "ask" line. I am going to email this exact handler home, and try tonight on another OS10.9 machine running LC 6.7. I have no idea if all this is important, but isn't it interesting?

Craig

Re: I just can't do it

Posted: Thu Apr 07, 2016 2:54 am
by dunbarx
Well,

Everything works fine now. It did not once, but does now. All you have to do is play around for a while, changing things, adding the word "quote" here and there, and then run the very first handle all over again.

Don't believe me? Me neither. I am fond of saying that I do not believe in ghosts. But twenty years ago, I surely heard one.

Craig