Execute two commands at the same time

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Fri Feb 03, 2017 1:20 pm

My message routine (command StartMessages) calls itself every-time after having shown all messages it gets from a database until I cancel the messageQueueID or if the label of a button is "Start" .
By pressing the button the user can opt to stop the routine (command StartMessages) that shows the messages.
This works fine until the user leaves a card without stopping this routine by pressing that button (and the user should not have to).

Because the command (handler) is stil running it goes into an error because the objects it refers to are not available anymore.

My question is: How can I stop the running of this command (handler) from the "on closeCard'' handler before I leave the card to prevent errors?

e.g. tried:

Code: Select all

Send "Exit StartMessages" to StartMessages
but this did not work even though the editor did not see an error in the syntax.
While running of-course i get the following error.
card "TheCardName": execution error at line 51 (Chunk: error in object expression) near "StartMessages", char 1

Regards,

Paul

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

Re: Execute two commands at the same time

Post by Klaus » Fri Feb 03, 2017 1:50 pm

Hi Paul,

do not rely on "visible" components like changing the LABEL of a button, use and set a local/global variable or a custom property
and check this before you "send" StartMessages again and "on closecard". Know what I mean?

Something like this in the card script:

Code: Select all

local stopit

on opencard
  put FALSE into stopit
end opencard

command StartMessages
  ## do your stuff here...
  if stopit <> TRUE then
    send "StartMessages" to me in XXX
  end if
end StartMessages

on closecard
  put TRUE into stopit
end closecard
Best

Klaus

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Fri Feb 03, 2017 3:32 pm

Initially this is what I did and now put back again, but still sometimes i get the(Chunk: no such object) error because the routine is stil not finished when going to another card via the Navigation Bar widget.
There is a 'Wait 3 seconds with messages' part in the routine. Maybe this could be solved better? But need this otherwise the messages move faster than they can de read :shock:

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

Re: Execute two commands at the same time

Post by Klaus » Fri Feb 03, 2017 3:42 pm

Please post your scrip(s) so we can see how we can fix it!

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Fri Feb 03, 2017 4:11 pm

Here is the code.....

This is the routine when I switch to another card.
the RCRPSv001CARD variable is an array variable I use to store data in for need in all card handlers (like global but then only for within a card). That is why I delete it before I leave.

Code: Select all

on closeCard
    put false into RCRPSv001CARD["SituationStartMessages"]
    cancel RCRPSv001CARD["MsgNbr"]
    set the label of button "ShowField2" to "Start"
    delete variable RCRPSv001CARD
end closeCard
This is the button script that starts or stops the messages

Code: Select all

global RCRPSv001,RCRPSv001CARD // Array with all important global stack and card variables
on mouseUp   
    if the label of me is "Stop"
    then
        put false into RCRPSv001CARD["SituationStartMessages"]
        cancel CRPSv001CARD["MsgNbr"]
        put empty into CRPSv001CARD["MsgNbr"]
        set the label of me to "Start"
        put empty into fld "RSS_1"
        put empty into fld "RSS_2"
        exit mouseUp
    else
        set the label of me to "Stop"
        put true into RCRPSv001CARD["SituationStartMessages"]
        StartMessages
    end if
end mouseUp
This is the command that calls itself to get the message data from DB (personal routine) and put into the RSS_# fields to show.

Code: Select all

command StartMessages
    // Get data from DB
    put RCRPSv001["DatabaseID"] into DatabaseID
    put empty into fld "RSS_1"
    put empty into fld "RSS_2"
    put "Situations" into TableName
    put "UniqueSituationID" into UniqueSingleKeyField
    put fld "PreferredGroup" into DataArrayKeyFields["ForGroupID"]
    put  "Active" into DataArrayKeyFields["Status"]
    put "SituationSubject" into SortByFields
    CheckHowmanyRecordsExistsV6 DatabaseID, TableName, UniqueSingleKeyField, DataArrayKeyFields, ResultFields, SortByFields, ASCDEC,OutExistsYesNo,OuttheFieldNames,OutNbrOfFields,OutNbrrecords,OutDataArrayRecords,OutResult,OutMsg
    if OutResult is "Error" 
    then
        answer "There was an Error while checking how many records already exists with message : " & OutMsg
        exit StartMessages
    end if
    if OutNbrrecords is 0 
    then 
        answer "No special situations to show!"
        set the label of me to "Start"
        put false into RCRPSv001CARD["SituationStartMessages"]
        cancel RCRPSv001CARD["MsgNbr"]
        put empty into RCRPSv001CARD["MsgNbr"]
        exit StartMessages
    end if
    put 1 into tCounter
    repeat for OutNbrrecords times
        if RCRPSv001CARD["SituationStartMessages"] is false
        then
            cancel RCRPSv001CARD["MsgNbr"]
            put empty into RCRPSv001CARD["MsgNbr"]
            exit StartMessages
        end if
        put OutDataArrayRecords[tCounter]["SituationSubject"]&": " into tLinetext
        put OutDataArrayRecords[tCounter]["Information"] after tLinetext
        if tCounter is 1 
        then 
            put tLinetext into tAllMessages
        else
            put cr & tLinetext after tAllMessages
        end if
        add 1 to tCounter
    end repeat
    -----------------------------------------------------------------
    put the number of lines in tAllMessages into tNumberOfLines
    repeat with tLineCounter =1 to tNumberOfLines
        if RCRPSv001CARD["SituationStartMessages"] is false
        then
            put empty into RCRPSv001CARD["MsgNbr"]
            cancel RRCRPSv001CARD["MsgNbr"]
            exit StartMessages
        end if
        put line tLineCounter of tAllMessages into tTheTextToShow
        if the visible of fld "RSS_2" is false
        then
            put  tTheTextToShow  into fld "RSS_2"
            lock screen for visual effect in rect (the rect of fld "RSS_1")
            Hide fld "RSS_1" 
            show fld "RSS_2" 
            unlock screen with visual effect push up
        else
            put  tTheTextToShow  into fld "RSS_1"
            lock screen for visual effect in rect (the rect of fld "RSS_2") 
            Hide fld "RSS_2" 
            show fld "RSS_1" 
            unlock screen with visual effect push up
        end if
        if RCRPSv001CARD["SituationStartMessages"] is false
        then
            cancel RCRPSv001CARD["MsgNbr"]
            put empty into RCRPSv001CARD["MsgNbr"]
            exit StartMessages
        else
            wait 3 seconds with messages // user needs time to read the message
        end if
    end repeat
    if RCRPSv001CARD["SituationStartMessages"] is true
    then
        send "StartMessages" to me
        put the result into RCRPSv001CARD["MsgNbr"]
    else
        cancel RCRPSv001CARD["MsgNbr"]
        put empty into RCRPSv001CARD["MsgNbr"]
        exit StartMessages
    end if
end StartMessages

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

Re: Execute two commands at the same time

Post by Klaus » Fri Feb 03, 2017 6:47 pm

Hi Paul,

a quick shot in the dark... :D

Handler "StartMessages", do not WAIT but send the message again in 3 seconds!

Code: Select all

...
        exit StartMessages
      ##else
      ##   wait 3 seconds with messages // user needs time to read the message
      end if
   end repeat
   if RCRPSv001CARD["SituationStartMessages"] = true then
      send "StartMessages" to me in 3 secs
      put the result into RCRPSv001CARD["MsgNbr"]
   else
      cancel RCRPSv001CARD["MsgNbr"]
      put empty into RCRPSv001CARD["MsgNbr"]
      exit StartMessages
   end if
end StartMessages
Best

Klaus

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Fri Feb 03, 2017 7:07 pm

The wait 3 sec is in-between each message. In queue there are already more messages so if i take away the wait 3 sec, all messages will be shown direct after each other. Then it waits 3 secs and retrieves all the messages again from DB and so on.
In this situation this is not a solution.... :?

But thanks though ...... :)

So there is no way to stop a running handler like we do within a handler with the exit statement from another handler (on closeCard) ? :?:

Regards,

Paul

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

Re: Execute two commands at the same time

Post by Klaus » Fri Feb 03, 2017 7:22 pm

Hi Paul,
mrcoollion wrote:The wait 3 sec is in-between each message. In queue there are already more messages so if i take away the wait 3 sec, all messages will be shown direct after each other. Then it waits 3 secs and retrieves all the messages again from DB and so on.
In this situation this is not a solution.... :?
ah, OK, sorry, I completely missed that the wait is in the REPEAT loop.
mrcoollion wrote:So there is no way to stop a running handler like we do within a handler with the exit statement from another handler (on closeCard) ? :?:
Not this way-

Another idea, add "... of cd "whatever the name of this card is"
after ALL references tp objects on that card.

Code: Select all

command StartMessages
   // Get data from DB
   put RCRPSv001["DatabaseID"] into DatabaseID
   put empty into fld "RSS_1" of cd "whatever..."
   put empty into fld "RSS_2" of cd "whatever..."
  ...
  repeat with tLineCounter =1 to tNumberOfLines
      if RCRPSv001CARD["SituationStartMessages"] is false then
         put empty into RCRPSv001CARD["MsgNbr"]
         cancel RRCRPSv001CARD["MsgNbr"]
         exit StartMessages
      end if
      put line tLineCounter of tAllMessages into tTheTextToShow
      if the visible of fld "RSS_2" is false then
         put  tTheTextToShow  into fld "RSS_2"of cd "whatever..."
         lock screen for visual effect in rect (the rect of fld "RSS_1")
         Hide fld "RSS_1" 
         show fld "RSS_2" 
         unlock screen with visual effect push up
      else
         put  tTheTextToShow  into fld "RSS_1"
         lock screen for visual effect in rect (the rect of fld "RSS_2"of cd "whatever...") 
         Hide fld "RSS_2" of cd "whatever..."
         show fld "RSS_1" of cd "whatever..."
         unlock screen with visual effect push up
      end if
...
Thsi way you should at least get no erros like "no such object..." which will occur after LC has already
navigated to the next card. Know what I mean?

Best

Klaus

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Fri Feb 03, 2017 10:06 pm

That is actually a good idea :D . I should have though of that :shock: .

need to add an additional 'or the short name of this card is not "TheCardName" ' otherwise the routine kept on running in the other card sometimes (because the card array RCRPSv001CARD["SituationStartMessages"] is deleted when leaving the card) , that gave really strange effects but it seems to work now....
I will test it better tomorrow... >>> Done some testing and have not got any errors yet :D .

Code: Select all

        if RCRPSv001CARD["SituationStartMessages"] is false or the short name of this card is not "CallRegistrations"
        then
            cancel RCRPSv001CARD["MsgNbr"]
            put empty into RCRPSv001CARD["MsgNbr"]
            exit StartMessages
        end if
Thanks ... :D

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute two commands at the same time

Post by mrcoollion » Wed Aug 02, 2017 8:22 pm

Found an alternative (easy?) way to make a ticker tape by using a browser widget and some html code.
This also opens many other ways to show text (left right up down ect....) as long as it is possible in html.
See attached example stack. (PS. I develop on windows 10 so check the code if you are not on windows)
HTMLScroller_V002.zip
Ticker Tape example with browser widget
(1.76 KiB) Downloaded 179 times
Here is a site you can get the html code from. There are many more if you search the internet :D
https://www.quackit.com/html/html_gener ... erator.cfm

Advantages:
- It does not intervene with anything the user does in the stack or card. It just keeps running without noticeable effect on the User Interface.
- You can use HTML formatting to make the text look special.

- Disadvantagec (as I see it):
- Takes more space than a regulair livecode field.
- Need to generate a local file as an URL for the browser.

Have fun with experimenting....

regards,

Paul

Post Reply

Return to “Talking LiveCode”