"send "ProgramScan" to me" bogs down my computer - Solved

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
DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

"send "ProgramScan" to me" bogs down my computer - Solved

Post by DR White » Fri Dec 23, 2022 12:23 pm

"send "ProgramScan" to me" bogs down my computer, even after I execute "cancel ProgamScanResult".

Am I doing something wrong or is there a better way to generate a program scan?

Thanks,

David

Code: Select all

on ProgramScan
   lock screen
   if PLC_Mode = 1 then
      send "ProgramScan" to me in 100 millisecond
      put the result into ProgamScanResult
      -- Program Update
      UpdateProgram
   else
      cancel ProgamScanResult
   end if
   unlock screen
end ProgramScan
------

Code: Select all

on UpdateProgram
   
   lock screen

   repeat with RungNumber = 1 to 1
      put "RungNumber = " & RungNumber & cr after fld "TextDisplay"
      repeat with tYCord = 1 to 4  -- X cordinate 
         put cr & cr after fld "TextDisplay"
         repeat with tXCord = 1 to 12  -- Y cordinate
            put cr & "XCord = " & tXCord & " - " after fld "TextDisplay"
            --Examine Object Type - stored in item 4 of array
            -- ** RungNumber,XCord,YCord,ObjectType,ObjectAddress,Data1,Data2,Data3,Data4,Data5,Data6,Data7 
            put item 4 of RungElement[RungNumber,tYCord,tXCord] into Test_1
            Switch Test_1
               -- Input Normally Open
               Case 4
                  put item 5 of RungElement[RungNumber,tYCord,tXCord] into Test_2
                  if char 1 of Test_2 = "I" then
                     put char -1 of Test_2 into Test_3
                     -- Identify the graphic 
                     put RungNumber & "_" & tYCord & "_" & tXCord & "_NO_True" into Test_4
                     -- Set Instruction TRUE indicator
                     if InputTable[Test_3] = "True" then
                        set vis of grc Test_4 to true
                     else
                        set vis of grc Test_4 to false
                     end if
                  end if
                  break
                  
                  -- Input Normally Closed
               Case 5
                  break
            end Switch
            
            --end repeat
         end repeat
      end repeat
   end repeat
   unlock screen
   
end UpdateProgram
-----
Last edited by DR White on Fri Dec 23, 2022 1:57 pm, edited 3 times in total.

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: "send "ProgramScan" to me" bogs down my computer

Post by DR White » Fri Dec 23, 2022 12:39 pm

Even changing "send "ProgramScan" to me in 100 millisecond" to send "ProgramScan" to me in 500 millisecond, my Mac CPU is at 100%.

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: "send "ProgramScan" to me" bogs down my computer

Post by DR White » Fri Dec 23, 2022 12:59 pm

It appears that my small "UpdateProgram" routine cannot be completed in 100 or even 500 milliseconds.

Is anyone else experiencing such issues?

Thanks,

David

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "send "ProgramScan" to me" bogs down my computer

Post by Klaus » Fri Dec 23, 2022 1:00 pm

Sorry, cannot help with this problem, but please use the CODE tags to make the script readable!
I did it for you here.

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: "send "ProgramScan" to me" bogs down my computer

Post by DR White » Fri Dec 23, 2022 1:44 pm

I removed the statements putting things into fld "TextDisplay" and it greatly increased the speed.
I would have thought that using "Lock Screen" would have kept this from being an issue, but apparently not the case.

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

Re: "send "ProgramScan" to me" bogs down my computer - Solved

Post by dunbarx » Fri Dec 23, 2022 2:48 pm

"Lock Screen" prevents LC from redrawing whatever changes might be made to the contents of the card. That is indeed a way to increase speed of execution.

Minimizing the number of changes to a field is another important improvement to speed in LC. Always do as much as possible within variables, and only, finally, at the end of as many processes as possible, load those changes into fields. This is most important within loops; do the work in a variable, and put the final result, after everything has run its course, into a field for user viewing.

Craig

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: "send "ProgramScan" to me" bogs down my computer - Solved

Post by stam » Sun Dec 25, 2022 12:06 am

DR White wrote:
Fri Dec 23, 2022 12:23 pm
Am I doing something wrong or is there a better way to generate a program scan?
Hi David,
What is a 'program scan'?

Skimming the posts above it seems that your handler 'updateProgram' may be the issue - but I'm really not clear what it is doing. Can you elaborate more on what this handler is doing? Perhaps someone can suggest a different algorithm, but difficult to know as your handler if fairly impenetrable to read.

S.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”