Page 1 of 1

Question on preOpenCard hilitedbutton

Posted: Sat May 04, 2013 8:37 pm
by shawnblc
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

Re: Question on preOpenCard hilitedbutton

Posted: Sat May 04, 2013 9:46 pm
by jmburnod
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

Re: Question on preOpenCard hilitedbutton

Posted: Sat May 04, 2013 10:30 pm
by shawnblc
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.

Re: Question on preOpenCard hilitedbutton

Posted: Sat May 04, 2013 11:08 pm
by shawnblc
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.

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 1:24 am
by phaworth
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 1:26 am
by shawnblc
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.

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 1:45 am
by shawnblc
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.

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 2:03 am
by PBH
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 2:08 am
by shawnblc
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.

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 2:41 am
by shawnblc
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 4:05 am
by Simon
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 12:43 pm
by Mark
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 3:39 pm
by jmburnod
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

Re: Question on preOpenCard hilitedbutton

Posted: Sun May 05, 2013 4:08 pm
by shawnblc
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.