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!
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?
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.
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
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
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?
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:
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:
"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
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.
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?
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.