Page 1 of 1
Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 04, 2015 5:33 pm
by tobx
Hi LiveCode!
Grad student researcher here - completely new to coding and trying to use LiveCode to set up a research experiment.
I'm trying to start with a main menu screen that has a pulldown menu with three items (each corresponding to a different card to jump to) and a confirmation button.
How can I keep the confirmation button disabled until a selection is made? I currently have the confirmation set to disabled and this code in the pulldown menu:
Code: Select all
on menuPick condselected
switch condselected
set the enabled of button "Confirm" to "true"
put condselected in gcondition
end switch
end menuPick
This seems like it should make the confirm button enable once a choice is made but nothing happens when I make a choice. Any tips would be appreciated!
Re: Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 04, 2015 7:20 pm
by dunbarx
Hi.
You have a little problem with the syntax of the switch construction. Try this:
Code: Select all
on mouseEnter
set the enabled of button "Confirm" to "false"
end mouseEnter
on menuPick condselected
switch condselected
put condselected in gcondition
end switch
set the enabled of button "Confirm" to "true"
end menuPick
Craig Newman
Re: Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 04, 2015 7:53 pm
by tobx
Ohhhhhh, it's better to disable in the script then enable goes after the switch end! Much appreciation, Craig - nailed it!
This next part is tricking me up, too. I want to select a condition in the main menu, go to a splash screen, then go to the card that corresponds to the choice made in the main menu.
I have the splash card set up (i.e., clicking confirm goes to splash card) but I can't figure out how to go from the splash card to the card that corresponds to the initial choice.
Right now I have declared the global variable "gcondition" in the main stack script:
...have the menu selection save into gcondition:
Code: Select all
on menuPick condselected
switch condselected
put condselected in gcondition
end switch
end menuPick
...then, in the splash screen, I have:
Code: Select all
on card open
wait 5 seconds
go to card "gcondition"
end card
...but nothing happens once I get to the splash screen.
tl;dr - how do I save the selection from the first card, then go to that selected card AFTER a splash screen?
Re: Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 04, 2015 9:18 pm
by dunbarx
on card open
Huh?
There may be other stuff to work on, but let's start with this.
Craig
Re: Pulldown menu --> splash screen ---> different cards
Posted: Fri Jun 05, 2015 11:59 am
by Klaus
Hi tobx,
1. welcome to the forum!
2. I recommend to check these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
3. No SWITCH neccessary at all if you do not actually "check/switch" the chosen menuitems:
Code: Select all
##on menuPick condselected
## switch condselected
## put condselected in gcondition
## end switch
##end menuPick
on menuPick condselected
put condselected in gcondition
end menuPick
Best
Klaus
Re: Pulldown menu --> splash screen ---> different cards
Posted: Fri Jun 05, 2015 7:07 pm
by tobx
dunbarx wrote:Huh?
Nice catch - I thought I copied that directly from a tutorial but I guess not. Thanks again, Craig!
Klaus wrote:Hi tobx,
1. welcome to the forum!
2. I recommend to check these stacks to get the basics of Livecode: [can't post links]
3. No SWITCH neccessary at all if you do not actually "check/switch" the chosen menuitems:
Code: Select all
##on menuPick condselected
## switch condselected
## put condselected in gcondition
## end switch
##end menuPick
on menuPick condselected
put condselected in gcondition
end menuPick
Best
Klaus
Hi Klaus! Really helpful stuff in that link, currently going through the menu and stack structure ones. Thanks!
I removed the switch lines as per your tip:
Code: Select all
global gcondition
on menuPick condselected
put condselected in gcondition
end menuPick
But now I'm getting an error: button "Condition": execution error at line 4 (Handler: can't find handler) near "in", char 8
This sounds like gcondition isn't being recognized as a variable even though it's declared in the first line. Saving condselected into gcondition will be super important for determining what card to go to after the splash screen so, as always, any advice appreciated!
Re: Pulldown menu --> splash screen ---> different cards
Posted: Fri Jun 05, 2015 7:17 pm
by SparkOut
"in" is not correct syntax for this statement.
Klaus was a little hasty in copy/pasting your snippet, he meant to correct it to:
put condselected INTO gcondition
You already had the intuitive syntax:
tobx wrote:Saving condselected into gcondition will be super important for determining what card to go to after the splash screen so, as always, any advice appreciated!
Re: Pulldown menu --> splash screen ---> different cards
Posted: Sat Jun 06, 2015 11:51 am
by Klaus
EX-ACTLY!

Re: Pulldown menu --> splash screen ---> different cards
Posted: Sun Jun 07, 2015 6:40 pm
by tobx
SparkOut wrote:INTO
Gah, such a tiny thing made all the difference! I really appreciate all of you helping me get started on this project. You're contributing to science!
I think this is the last major roadblock I'm hitting for this topic: how to go from the splash screen to the card that corresponds to the menu choice. Here's what I have on the splash screen:
Code: Select all
on openCard
wait 5 seconds
if gcondition = "Tie" then
go to card "Tie"
end if
if gcondition = "Take" then
go to card "Take"
end if
if gcondition = "Give" then
go to card "Give"
end if
end openCard
Assuming my saving of the menu choice into the global gcondition variable (code in posts above) was correct, I should idle on the splash screen for 5 seconds then go to that saved card. I checked the card names and menu options for spelling and formatting; however, as you could probably guess, nothing happens after 5 seconds. Any tips?
Re: Pulldown menu --> splash screen ---> different cards
Posted: Sun Jun 07, 2015 7:07 pm
by Klaus
Hi tobx,
did you declare gConditon in the abvove mentioned "opencard" script? See below.
Are these cards "Tie" etc. really part of the stack with the "opencard" script?
Know what I mean? Or maybe that is the "splash" screen"?
Besdies the fact that it doesn't work currently, you can also have this shorter:
Code: Select all
global gConditon
on openCard
wait 5 seconds
go cd gcondition
end openCard
Best
Klaus
Re: Pulldown menu --> splash screen ---> different cards
Posted: Sun Jun 07, 2015 7:26 pm
by tobx
Klaus wrote:Hi tobx,
did you declare gConditon in the abvove mentioned "opencard" script? See below.
Are these cards "Tie" etc. really part of the stack with the "opencard" script?
Know what I mean? Or maybe that is the "splash" screen"?
Besdies the fact that it doesn't work currently, you can also have this shorter:
Code: Select all
global gConditon
on openCard
wait 5 seconds
go cd gcondition
end openCard
Best
Klaus
Oh, I thought I only had to declare the global variable once on the main stack script. I added the declaration to the splash card and it works now! Thanks so much Klaus, that shortening of the code also really helps!
Re: Pulldown menu --> splash screen ---> different cards
Posted: Sun Jun 07, 2015 10:04 pm
by dunbarx
Hi.
This has tripped others used to different languages. Globals must be declared in each script they are used, and above any handlers that might call them. Similarly, script locate variables must be declared above handlers in a particular script.
Check out custom properties, which are far more powerful, and once set are available anywhere anytime, and further, survive sessions.
Craig Newman
Re: Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 11, 2015 7:03 pm
by tobx
I'm stuck again
I'm on the card where participants hit the space bar to earn points. I want them to only be on this page for 10 seconds. "gcondition" was declared and saved from an earlier menu to determine what card to go to after this current one. gcondition works, but it isn't doing anything with the send command in the last line:
Code: Select all
global gcondition
on openCard
put "0" into field "Score"
end openCard
on keyDown spacebar
if the enableAddScore of this card = "true" then add 1 to fld "Score"
set the enableAddScore of this card to "false"
end keyDown
on rawKeyUp tKey
if tKey is 32 then set the enableAddScore of this card to "true"
end rawKeyUp
send "go cd gcondition" in 10 seconds
I know the problem is with that last line: using the send command. I tried using the wait command but it freezes the key press detection. Any tips?
Re: Pulldown menu --> splash screen ---> different cards
Posted: Thu Jun 11, 2015 7:14 pm
by Klaus
Hi tobx,
couple of issues:
1. your last line needs to be INSIDE of a handler!
And you need to supply a recipient, see below
Code: Select all
global gcondition
on openCard
put "0" into field "Score"
send "go cd gcondition" TO ME in 10 seconds
end openCard
...
This does not work as you might exspect!
Code: Select all
on keyDown spacebar
if the enableAddScore of this card = "true" then add 1 to fld "Score"
set the enableAddScore of this card to "false"
end keyDown
This handler come with one parameter: the key pressed, whcih may or may be NOT a spacebar!
Change like this:
Code: Select all
on keyDown tKeyPressed
## Check if it was SPACE and only proceed if this actually WAS SPACE
if tKeyPressed <> SPACE then
pass keydown
end if
if the enableAddScore of this card = "true" then add 1 to fld "Score"
set the enableAddScore of this card to "false"
end keyDown
At least this is how I understand the script
Best
Klaus
Re: Pulldown menu --> splash screen ---> different cards
Posted: Fri Jun 12, 2015 6:16 pm
by tobx
Klaus wrote:
1. your last line needs to be INSIDE of a handler!
And you need to supply a recipient, see below
Code: Select all
on openCard
put "0" into field "Score"
send "go cd gcondition" TO ME in 10 seconds
end openCard
...
Hi Klaus! I've been following BYU's tutorial on Timing (it explains the send vs wait functions) and tried this earlier to no avail. I've tried it again now (putting the send line inside the openCard area with "to me" and even "to this card") and it does not go to the appropriate card after 10 seconds. I know gcondition is set correctly (I've tested it using other commands) so I think there has to be something wrong with how I have the send command written here! Perhaps there is some strange interaction with other code you might be able to spot?
This handler come with one parameter: the key pressed, whcih may or may be NOT a spacebar!
Change like this:
Code: Select all
on keyDown tKeyPressed
## Check if it was SPACE and only proceed if this actually WAS SPACE
if tKeyPressed <> SPACE then
pass keydown
end if
if the enableAddScore of this card = "true" then add 1 to fld "Score"
set the enableAddScore of this card to "false"
end keyDown
The code I have currently for the space bar only detects space bar presses for the score (with some help from another thread) but I'll try this out. Thanks, Klaus!