getting mouseUp to be more responsive

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
seanmiller
Posts: 50
Joined: Mon Mar 03, 2014 1:17 am

getting mouseUp to be more responsive

Post by seanmiller » Thu Apr 28, 2016 7:22 pm

Howdy fellow LiveCoders,

I'm wrestling with an issue that I thought some of you may have also experienced. I'm building an app to deploy to Android and iOS. It has a card where a user evaluates a student, giving various items a score from 1 to 4. I've set these items as grouped rows where the scores are also groups. By pressing "1", for example, that group gets selected and the other numbered groups are deselected. mouseUp here also performs a few handlers to do some calculations. Here's the relevant code:

For each of the 4 "buttons":

Code: Select all

// app color scheme
global gColor1, gColor2, gColor3, gColor4, gColor5, gColor6, gColor7, gColor8, gColor9

global gScoreButtonSelected, gBehaviorScores, gStudentDriveBehaviorScores, gObjectiveSelected,gDriveBehaviors, gReadOnly

on mouseUp
   lock screen
   if gReadOnly is true then
      exit mouseUp
      else
   if gScoreButtonSelected is not 1 then
      resetScoreButtons
      set the backgroundColor of graphic "scoreCircle" of me to gColor4
      put 1 into gScoreButtonSelected
      put field "behaviorButtonNumber" of me into tBehaviorButtonNumber
      put 1 into field "behaviorScore" of group ("behaviorButton" & tBehaviorButtonNumber) of card "assessment"
   else
      set the backgroundColor of graphic "scoreCircle" of me to gColor2
      put empty into gScoreButtonSelected
      put field "behaviorButtonNumber" of me into tBehaviorButtonNumber
      put empty into field "behaviorScore" of group ("behaviorButton" & tBehaviorButtonNumber) of card "assessment"
end if
generateStudentDriveBehaviorScores
calculateObjectiveScore
end if
unlock screen
end mouseUp
On a group that contains the "buttons":

Code: Select all

// app color scheme
global gColor1, gColor2, gColor3, gColor4, gColor5, gColor6, gColor7, gColor8, gColor9

on resetScoreButtons
   set the backgroundColor of graphic "scoreCircle" of the group "scoreButton1" of me to gColor2
   set the backgroundColor of graphic "scoreCircle" of the group "scoreButton2" of me to gColor2
   set the backgroundColor of graphic "scoreCircle" of the group "scoreButton3" of me to gColor2
   set the backgroundColor of graphic "scoreCircle" of the group "scoreButton4" of me to gColor2
end resetScoreButtons
And on the stack script, the code for the called handlers:

Code: Select all

on generateStudentDriveBehaviorScores
   put empty into gStudentDriveBehaviorScores
   set itemDel to tab
   repeat with x = 1 to the number of lines of gDriveBehaviors
      put item 6 of line x of gDriveBehaviors into tBehaviorButtonNumber
      if field "behaviorScore" of group ("behaviorButton" & tBehaviorButtonNumber) of card "assessment" is not empty then
         put item 2 of line x of gDriveBehaviors after gStudentDriveBehaviorScores
         put tab & field "behaviorScore" of group ("behaviorButton" & tBehaviorButtonNumber) of card "assessment" after gStudentDriveBehaviorScores
         put tab & item 7 of line x of gDriveBehaviors & return after gStudentDriveBehaviorScores
         end if
   end repeat
end generateStudentDriveBehaviorScores

Code: Select all

on calculateObjectiveScore
   set itemDel to tab
   put 0 into tTotalBehaviorsToScore
   put 0 into tRunningObjectiveScore
   
   repeat with x = 1 to the number of lines of gStudentDriveBehaviorScores
      put item 3 of line x of gStudentDriveBehaviorScores into tObjectiveSequence
      
      if tObjectiveSequence = gObjectiveSelected then
         put item 2 of line x of gStudentDriveBehaviorScores into tBehaviorScore
         add tBehaviorScore to tRunningObjectiveScore
         add 1 to tTotalBehaviorsToScore
         end if
      end repeat

      if tTotalBehaviorsToScore is not 0 then
         
put tRunningObjectiveScore / tTotalBehaviorsToScore into tTotalObjectiveScore

if tTotalObjectiveScore <= 1.25 then
   // 4 stars
   repeat with x = 1 to 4
      set the visible of image ("star" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
      set the visible of image ("halfstar" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   end repeat

else if tTotalObjectiveScore > 1.25 and tTotalObjectiveScore <= 1.75 then
   // 3 1/2 stars
      repeat with x = 1 to 3
      set the visible of image ("star" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
      set the visible of image ("halfstar" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   end repeat
   set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
   
else if tTotalObjectiveScore > 1.75 and tTotalObjectiveScore <= 2.25 then
   // 3 stars
         repeat with x = 1 to 3
      set the visible of image ("star" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
      set the visible of image ("halfstar" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   end repeat
   set the visible of image "star4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
      set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   
else if tTotalObjectiveScore > 2.25 and tTotalObjectiveScore <= 2.75 then
   // 2 1/2 stars
 set the visible of image "star1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
 set the visible of image "halfstar1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
  set the visible of image "star2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
  set the visible of image "halfstar2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "star3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "halfstar3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
    set the visible of image "star4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
      set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   
else if tTotalObjectiveScore > 2.75 and tTotalObjectiveScore <= 3.25 then
   // 2 stars
    set the visible of image "star1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
 set the visible of image "halfstar1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
  set the visible of image "star2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
  set the visible of image "halfstar2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "star3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "halfstar3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "star4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    
else if tTotalObjectiveScore > 3.25 and tTotalObjectiveScore <= 3.75 then
   // 1 1/2 stars
    set the visible of image "star1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
 set the visible of image "halfstar1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
  set the visible of image "star2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
  set the visible of image "halfstar2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "star3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "halfstar3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "star4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    
else if tTotalObjectiveScore > 3.75 then
   // 1 star
    set the visible of image "star1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to true
 set the visible of image "halfstar1" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
  set the visible of image "star2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
  set the visible of image "halfstar2" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "star3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   set the visible of image "halfstar3" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "star4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
    set the visible of image "halfstar4" of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
 end if
   else
    // no score
   repeat with x = 1 to 4
      set the visible of image ("star" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
      set the visible of image ("halfstar" & x) of group ("objectiveButton" & gObjectiveSelected) of card "assessment" to false
   end repeat
end if
end calculateObjectiveScore
As you can see, each mouseUp refreshes a score for that particular row item, represented by a star rating. The issue is that the "buttons" are slow to respond. If the user presses a button, when she presses another, it doesn't immediately respond or she has to tap on it twice to get it to change color. Is this because of the handlers that run on each mouseUp--that they're processor-intensive?

Any suggestions on how to make the "buttons" more responsive would be most appreciated!

Regards,
Sean
Last edited by seanmiller on Thu Apr 28, 2016 8:22 pm, edited 1 time in total.

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

Re: getting mouseUp to be more responsive

Post by jmburnod » Thu Apr 28, 2016 8:13 pm

Hi Sean,

I dont see a lock screen in your scripts.
I think you can try lock screen to accelerate process
Best regards
Jean-Marc

seanmiller
Posts: 50
Joined: Mon Mar 03, 2014 1:17 am

Re: getting mouseUp to be more responsive

Post by seanmiller » Thu Apr 28, 2016 8:24 pm

Hi Jean-Marc,

Thanks for the tip. I accidentally cut off a couple lines from the bottom of the first script--the script associated with the "buttons". It does lock and unlock the screen within the mouseUp. Doesn't seem to make a difference.

Sean

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

Re: getting mouseUp to be more responsive

Post by jmburnod » Thu Apr 28, 2016 8:40 pm

Hi Sean
Doesn't seem to make a difference.
what about "repeat for each" instead "repeat with" ?
Jean-Marc

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

Re: getting mouseUp to be more responsive

Post by dunbarx » Thu Apr 28, 2016 8:42 pm

Hi.

I just glanced at your handlers. It may be a case of field and object references within repeat loops. I have no idea how long those loops are. But since you build those references on the fly, it is more complicated than the simple:

"Move ALL of the object references out of the repeat loops"

How long are those loops? LC is pretty fast...

Craig Newman

seanmiller
Posts: 50
Joined: Mon Mar 03, 2014 1:17 am

Re: getting mouseUp to be more responsive

Post by seanmiller » Thu Apr 28, 2016 8:57 pm

Hi Craig,

gDriveBehaviors (in the handler generateStudentDriveBehaviorScores) has around 20 to 30 lines in it.

gStudentDriveBehaviorScores (in the handler calculateObjectiveScore) has from 5 to 10 lines in it.

The idea is that each assessment has a certain number of "behaviors" that are organized into "objectives". So the app, with each mouseUp, is calculating a score for an objective from its subsidiary behaviors.

Sean

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

Re: getting mouseUp to be more responsive

Post by dunbarx » Thu Apr 28, 2016 10:19 pm

Hmmm.

Response should be instantaneous.

Craig

seanmiller
Posts: 50
Joined: Mon Mar 03, 2014 1:17 am

Re: getting mouseUp to be more responsive

Post by seanmiller » Thu Apr 28, 2016 11:44 pm

That's what I assumed too...

Do you think it might have something to do with the fact that I'm using groups containing fields as "buttons", rather than actual buttons?

Sean

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

Re: getting mouseUp to be more responsive

Post by dunbarx » Fri Apr 29, 2016 2:08 pm

Hi.

I can only suggest that you try to comment out lines, either in small groups or one-by-one, and see if a sudden "normal" response comes back. Your handlers have only a very small number of controls, and the processes you are running should not take any time at all.

Or maybe post the stack, making sure it "runs" for others, that is, that all relevant data is resident?

Craig

Post Reply

Return to “Talking LiveCode”