Question on preOpenCard hilitedbutton

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Question on preOpenCard hilitedbutton

Post by shawnblc » Sat May 04, 2013 8:37 pm

I have the following code on preOpenCard, but would like to be able to offer a student to go back and review their answers on their quiz. With the following code it resets the group to 0. How would I go about keeping their selected answer chosen while they review their quiz, but could change it if they wanted to?

Code: Select all

on preOpenCard
  set the hilitedbutton of grp "grpA1" to 0
end preOpenCard

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2376
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Question on preOpenCard hilitedbutton

Post by jmburnod » Sat May 04, 2013 9:46 pm

Hi shawnbic,
You have to store the result in a global variable or a customproperty and use it to set the hilitedbutton.
Something like that

Code: Select all

on preopencard
   set the hilitedbutton of group "grdA1" to the uMyAnswer of this cd
end preopencard

on closecard
   set the uMyAnswer of this cd to the hilitedbutton of group "grdA1"
end closecard
Best regards
Jean-Marc

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sat May 04, 2013 10:30 pm

jmburnod wrote:Hi shawnbic,
You have to store the result in a global variable or a customproperty and use it to set the hilitedbutton.
Something like that

Code: Select all

on preopencard
   set the hilitedbutton of group "grdA1" to the uMyAnswer of this cd
end preopencard

on closecard
   set the uMyAnswer of this cd to the hilitedbutton of group "grdA1"
end closecard
Best regards
Jean-Marc

Jean-Marc that worked like a champ. Thank you.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sat May 04, 2013 11:08 pm

When my quiz is restarted it appears that the last chosen answers are still showing. If I add the following code though to the start quiz button I get an error. What am I doing wrong?

Code: Select all

on mouseUp
   go to card question1
   set the hilitedbutton of grp "grpA1" to 0
   set the hilitedbutton of card "question2" grp "grpA2" to 0
   set the hilitedbutton of card "question3" grp "grpA3" to 0
end mouseUp
Tried this too.

Code: Select all

   go to card question1
   set the hilitedbutton of grp "grpA1" to 0
   set the hilitedButton of grp "grpA2" card "question2" to 0
Neither is working when the quiz is restarted.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Question on preOpenCard hilitedbutton

Post by phaworth » Sun May 05, 2013 1:24 am

Hi Shawn,
The first block of code has the the grp and card references the wrong way round, should be grp "xxx" of card "abc".

Not sure why the second block doesn't work (except maybe no "of" before the card reference?) but I think I saw you had some preOpenCard stuff so maybe that overrides what you're doing. In general, I'd put card initialsation stuff in preOpenCard and not in the object the card is opened from.

HTH,

Pete

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sun May 05, 2013 1:26 am

phaworth wrote:Hi Shawn,
The first block of code has the the grp and card references the wrong way round, should be grp "xxx" of card "abc".

Not sure why the second block doesn't work (except maybe no "of" before the card reference?) but I think I saw you had some preOpenCard stuff so maybe that overrides what you're doing. In general, I'd put card initialsation stuff in preOpenCard and not in the object the card is opened from.

HTH,

Pete
Let me try this and I'll update you. Thanks for the response.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sun May 05, 2013 1:45 am

Thanks for the response Pete, unfortunately I still can't get things like I'd like them. When the stack is closed it's remembering the answers instead of setting hilitedButton to 0. Guess I'll continue messing around with it. It's a learning experience. What I'm wanting to do isn't complicated. I simply want users to be able to review their quiz which is working, but when the stack is closed I want the hilitedButton to 0 on all cards.

PBH
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 97
Joined: Sun Feb 20, 2011 4:26 pm
Location: Vancouver Island, BC, Canada. ex.UK
Contact:

Re: Question on preOpenCard hilitedbutton

Post by PBH » Sun May 05, 2013 2:03 am

Shawn,

There is a 'closeStack' message available too. You can use this to add clean-up stuff if necessary.

Is this just a problem in the IDE or do you have the same issue when you build a standalone?

Paul

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sun May 05, 2013 2:08 am

PBH wrote:Shawn,

There is a 'closeStack' message available too. You can use this to add clean-up stuff if necessary.

Is this just a problem in the IDE or do you have the same issue when you build a standalone?

Paul
I haven't tried to build a standalone yet. So far it's only in the IDE.

UPDATE: I just built a standalone and the problem still persists.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sun May 05, 2013 2:41 am

I don't understand why the last two lines won't work. My preOpenCard scripts follow the same in each card even if changed to on openCard. Hmmmmm.

Code: Select all

on mouseUp
   go to card question1 -- works
   set the hilitedButton of grp "grpA1" to 0  -- works
   set the hilitedButton of grp "grpA2" of card "question2" to 0  -- does not work
   set the hilitedButton of grp "grpA3" of card "question3" to 0  -- does not work
end mouseUp

My preOpenCard is ----> which follows the same on each card.

Code: Select all


on OpenCard
     set the hilitedbutton of grp "grpA1" to the gStudentAnswerQ1 of this card
end OpenCard

on closeCard
   set the gStudentAnswerQ1 of this card to the hilitedbutton of group "grpA1"
   --set the hilitedbutton of grp "grpA1" to 0
end closeCard

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Question on preOpenCard hilitedbutton

Post by Simon » Sun May 05, 2013 4:05 am

Hi shawnblc,
I'd put setting of the highlighted state in the preOpenCard. As it is preOpen everything will get populated correctly before you actually see the card.

I'm going to make a wild guess that it may be the last state you save your stack in that causing some confusion. If you unhighlight all the buttons on the card and then save, you will assume that your code is working when returning to that card and seeing the correct state.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Question on preOpenCard hilitedbutton

Post by Mark » Sun May 05, 2013 12:43 pm

Hi,

First of all, when you write "it doesn´t work", you always need to write 1) what did you expect to happen and 2) what happened instead. Never just write "it doesn't work". It is the main reason why questions take much longer to be answered than actually necessary,

A possible reason why your code "doesn´t work" is that the hcBehavior of the group(s) is true or the sharedHilited of the buttons is true. Set both of them to false and I'd expect your code to work (provided that there are no additional problems). When I test this, I don't get an execution error.

Howoever, if you set the hilitedButton of a group and then open the card where the group is located, the preOpenCard script sets the hilitedButton again and it would seem that your previous script didn't even run. Therefore, you need to reset all custom properties:

Code: Select all

on mouseUp
   go to card "question1"
   set the hilitedButton of grp "grpA1" to 0
   set the gStudentAnswerQ1 of this card to the hilitedbutton of group "grpA1"
   set the hilitedButton of grp "grpA2" of card "question2" to 0
   set the gStudentAnswerQ2 of  card "question2" to 0
   set the hilitedButton of grp "grpA3" of card "question3" to 0
   set the gStudentAnswerQ3 of  card "question3" to 0
end mouseUp
I have the custom property of each card a different name in this script, but there's no need for that. Each card has its own custom property and you can use the same names for those properties.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2376
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Question on preOpenCard hilitedbutton

Post by jmburnod » Sun May 05, 2013 3:39 pm

Hi shawnblc ,
You can also use a file to store the results for each student and read it at preopenstack.
For exemple one file per student, one line per card "namecard,answer1,answer2, etc...
At the same time you do a "results report" which should be useful.
Best
Jean-Marc
Last edited by jmburnod on Sun May 05, 2013 4:43 pm, edited 1 time in total.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 334
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Question on preOpenCard hilitedbutton

Post by shawnblc » Sun May 05, 2013 4:08 pm

Thanks for all the help guys. Sorry for my lack of LiveCode knowledge or programming knowledge in general. I guess if I knew what in the heck I was talking about I'd better be able to express what's happening. Thanks again. On to learning more.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”