Pulldown menu --> splash screen ---> different cards

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
tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Pulldown menu --> splash screen ---> different cards

Post by tobx » Thu Jun 04, 2015 5:33 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by dunbarx » Thu Jun 04, 2015 7:20 pm

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

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Thu Jun 04, 2015 7:53 pm

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:

Code: Select all

global gcondition
...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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by dunbarx » Thu Jun 04, 2015 9:18 pm

on card open
Huh?

Code: Select all

on openCard
There may be other stuff to work on, but let's start with this.

Craig

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pulldown menu --> splash screen ---> different cards

Post by Klaus » Fri Jun 05, 2015 11:59 am

Hi tobx,

1. welcome to the forum! :D

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

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Fri Jun 05, 2015 7:07 pm

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

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!

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

Re: Pulldown menu --> splash screen ---> different cards

Post by SparkOut » Fri Jun 05, 2015 7:17 pm

"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!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pulldown menu --> splash screen ---> different cards

Post by Klaus » Sat Jun 06, 2015 11:51 am

EX-ACTLY! :D

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Sun Jun 07, 2015 6:40 pm

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?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pulldown menu --> splash screen ---> different cards

Post by Klaus » Sun Jun 07, 2015 7:07 pm

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


Best

Klaus

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Sun Jun 07, 2015 7:26 pm

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


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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by dunbarx » Sun Jun 07, 2015 10:04 pm

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

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Thu Jun 11, 2015 7:03 pm

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?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pulldown menu --> splash screen ---> different cards

Post by Klaus » Thu Jun 11, 2015 7:14 pm

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

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


Best

Klaus

tobx
Posts: 16
Joined: Thu Jun 04, 2015 5:17 pm

Re: Pulldown menu --> splash screen ---> different cards

Post by tobx » Fri Jun 12, 2015 6:16 pm

Klaus wrote: 1. your last line needs to be INSIDE of a handler!
And you need to supply a recipient, see below :D

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!

Post Reply