Changing Card location & saving field input ??

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

Post Reply
ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Changing Card location & saving field input ??

Post by ValiantCuriosity » Mon Mar 11, 2019 8:23 pm

Hello Good People! :D

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








/
May I never be cured of my curiosity! :D

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Changing Card location & saving field input ??

Post by Klaus » Mon Mar 11, 2019 8:30 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Changing Card location & saving field input ??

Post by dunbarx » Mon Mar 11, 2019 8:36 pm

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

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Changing Card location & saving field input ??

Post by ValiantCuriosity » Mon Mar 11, 2019 9:26 pm

Thanks guys,

Renumbering the cards worked! :D

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
May I never be cured of my curiosity! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Changing Card location & saving field input ??

Post by dunbarx » Mon Mar 11, 2019 9:39 pm

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

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Changing Card location & saving field input ??

Post by Klaus » Mon Mar 11, 2019 9:50 pm

Yes, what exactly did you script in the field?

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Changing Card location & saving field input ??

Post by ValiantCuriosity » Mon Mar 11, 2019 10:05 pm

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. :wink:

Onward and Upward,
-Rachel
May I never be cured of my curiosity! :D

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Changing Card location & saving field input ??

Post by Klaus » Mon Mar 11, 2019 10:27 pm

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! :-D

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Changing Card location & saving field input ??

Post by dunbarx » Mon Mar 11, 2019 10:28 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Changing Card location & saving field input ??

Post by dunbarx » Mon Mar 11, 2019 10:30 pm

Klaus.

I thought the issue was that she could not type into the field.

Rachel?

Craig

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Changing Card location & saving field input ??

Post by SparkOut » Mon Mar 11, 2019 10:32 pm

@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.

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Changing Card location & saving field input ??

Post by ValiantCuriosity » Mon Mar 11, 2019 11:11 pm

Klaus,

That nailed it! Thank you. I'm happy dancing.
HappyDance.png
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
May I never be cured of my curiosity! :D

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Changing Card location & saving field input ??

Post by Klaus » Tue Mar 12, 2019 12:27 am

ValiantCuriosity wrote:
Mon Mar 11, 2019 11:11 pm
That nailed it!
YO! :D

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***. 8)

*** Whatever fits the current situation.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”