Page 1 of 1
Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 8:23 pm
by ValiantCuriosity
Hello Good People!
I have two very basic questions. I know that I've seen the answers before, but after about 1.5 hours searching, I can't find them again. 368 possibilities in the forum. I made it through about 20.

Plus my documents, the dictionary, some LC lessons. I give up. I am going to overburden the forum again.
Question 1: I have 3 cards. I want to change the location of card 2 (the middle card) to become card 3 (the end card). That means that card 3 will become the middle card.
Question 2: I'm recreating the LC lesson for "Story Book". I don't want to use the ask alert box. I want to get the input from fields.
How do I get the user input of field "name" and save it to my global variable gName?
I've attempted quite a few variations and things. Some are from reading and others from this forum.
I've tried "get" and then "put", but I think that I need to recognize the field input in some way before entering it into the variable.
Code: Select all
put text of field "AuthorName" into gName
TIA
Your eternal noob,
-Rachel
/
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 8:30 pm
by Klaus
Hi Rachel,
1. Just set the number of your card(s):
Code: Select all
...
set the number of cd 2 to 3
...
2. Never forget that in LC you need to declare a global variable in every script you use it in:
Code: Select all
global gName
...
put THE text of field "AuthorName" into gName
## or just:
put field "AuthorName" into gName
...
Best
Klaus
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 8:36 pm
by dunbarx
What Klaus said.
Also, never forget that in LC you need to declare a global variable (and script local variables) ABOVE every handler you use it in.
This is common practice, though there may be occasions, especially with script local variables, where it is advantageous to place them somewhere in the interior of a script, so that any handlers above the declaration do not see it.
Craig Newman
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 9:26 pm
by ValiantCuriosity
Thanks guys,
Renumbering the cards worked!
I think I am still doing something wrong with the field. (Big surprise, huh?)
When I run the program and type into the field, it doesn't "remember" or recognize the text that I typed into the field. I used the code that was recommended by Klaus, but it isn't being recognized. I think I must be missing a step here.
Oh, and, the code is in the field.
Double "OH". Yes, I learned that about globals the hard, head banging way.
Sigh,
-Rachel
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 9:39 pm
by dunbarx
Rachel.
Is the field editable? That is, it is not locked?
And you do not have any keydown, keyUp, or anything like that in the field script?
And make sure the "traversalOn" in enabled.
Craig
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 9:50 pm
by Klaus
Yes, what exactly did you script in the field?
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 10:05 pm
by ValiantCuriosity
OK, Klaus and Craig...
Here you go:
Is the field editable?
1. Yes. The field is editable.
And you do not have any keydown, keyUp, or anything like that in the field script?
2. Nothing like the above in the script field or elsewhere.
And make sure the "traversalOn" in enabled.
3. It's on.
Yes, what exactly did you script in the field?
Code: Select all
global gName
put the text of field "AuthorName" into gName
I have nothing else in the field code. There is no trigger like a button. Maybe I need one. I'm having a lot of trouble understanding the event triggers in LiveCode. The button is easy, but there are a lot of times when I don't want to trigger every event with a button.
Onward and Upward,
-Rachel
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 10:27 pm
by Klaus
ValiantCuriosity wrote: ↑Mon Mar 11, 2019 10:05 pm
I have nothing else in the field code. There is no trigger like a button. Maybe I need one.
You BET!
You can use e.g. -> on textchanged
That message will get triggered when you enter text.
Try this in the fields script:
Code: Select all
global gName
on textchanged
## put the text of field "AuthorName" into gName
## or, if this IS field "AuthorName"
put the text of ME into gName
end textchanged
Best
Klaus
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 10:28 pm
by dunbarx
Rachel.
Do you get a blinking cursor in the field when it is in focus? For that matter, does the field focus?
Just as a test, from msg, "put "XYZ" into field "yourTroublsesomeField"
Craig
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 10:30 pm
by dunbarx
Klaus.
I thought the issue was that she could not type into the field.
Rachel?
Craig
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 10:32 pm
by SparkOut
@Rachdk
But there has to be a handler, to catch and respond to whatever event you determine.
The statement you put in the field script "like that" will never be triggered. It needs to be in a handler that deals with some message or other.
Events that trigger messages in (unlocked) fields include "textChanged", "closeField", "keyDown", "rawKeyDown", etc etc.
So you have to choose what event to catch, depending on your user interface and how it will affect the program control.
eg, if you want any change in the text to update the global variable, make the field script include a "textChanged" handler with your script line inside that handler. In which case, as the user types the name "Fred" the handler will fire when the user types "F" which changes the text from empty, then again when "r" is typed. Etc,etc. Or choose another event that fires a message to handle, according to your needs.
Look in the dictionary and filter the type to show messages. There are an awful lot of events that trigger messages that you can catch with your handlers. This is a blessing, not a problem.
Re: Changing Card location & saving field input ??
Posted: Mon Mar 11, 2019 11:11 pm
by ValiantCuriosity
Klaus,
That nailed it! Thank you. I'm happy dancing.
Sparkout,
Thank you for the complete explanation and, best of all, where to find a list in the Dictionary. This is definitely a problem with me not knowing how to use the handlers in LC.
Now, I'm off to cook up more questions.
Thanks again to everyone.
-Rachel
Re: Changing Card location & saving field input ??
Posted: Tue Mar 12, 2019 12:27 am
by Klaus
YO!
For the future, when I put some dots at the beginning and end of my code snippets -> ...
that means that you have to replace them with a trigger (sic!) of your choice***.
*** Whatever fits the current situation.