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
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Apr 04, 2016 8:49 pm
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
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Mon Apr 04, 2016 9:11 pm
That should work without the "do", no?
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Apr 04, 2016 9:21 pm
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
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Mon Apr 04, 2016 9:27 pm
What happens if you put parens around it, e.g.:
put (it & "x") into tChunk
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Apr 04, 2016 10:08 pm
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
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Tue Apr 05, 2016 7:59 pm
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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Tue Apr 05, 2016 9:02 pm
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

https://alternatic.ch
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Apr 05, 2016 10:51 pm
@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?
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Tue Apr 05, 2016 11:05 pm
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Apr 05, 2016 11:47 pm
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:
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
-
mwieder
- VIP Livecode Opensource Backer

- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
-
Contact:
Post
by mwieder » Wed Apr 06, 2016 1:08 am
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"
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 06, 2016 3:07 am
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
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Wed Apr 06, 2016 9:19 am
@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
@ Jaqueline
Here is the stack i used (LC 7.06, OS X 10.10.3)
Best regards
Jean-Marc
-
Attachments
-
- OneTestGraig.livecode.zip
- (1.62 KiB) Downloaded 187 times
https://alternatic.ch
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Wed Apr 06, 2016 1:49 pm
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
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Apr 07, 2016 2:54 am
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
Last edited by
dunbarx on Thu Apr 07, 2016 8:49 pm, edited 1 time in total.