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

Execute two commands at the same time

Post by mrcoollion » Tue Jan 24, 2017 9:16 pm

Is there any way to have two (or more) commands executed at the same time.
What I want to do is to show / hide two fields at the same time with visual effects.

I have been looking at broadcasting but cannot figure that out (need GLX framework plugin ect....)

Regards,

Paul

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

Re: Execute two commands at the same time

Post by Klaus » Tue Jan 24, 2017 9:40 pm

Goedenavond Paul,

sounds like you are looking for something like this:
...
lock screen for visual effect
hide fld 1
hide fld 2
unlock screen with visual effect dissolve
...
Right?


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 » Tue Jan 24, 2017 10:05 pm

Goedenavond Klaus,


What I want to do is push up text in a field by using visual effect push up.
In this case for showing a RSS feed (as a test) because the push up affect is nice and smooth.
To give the user the idea that the new text pushes the old text up I need to hide one field with visual effect push up and at the same time show the second field with visual effect push up.
Both fields are transparent and a third field provides the background color.
I does work after each other but that leaves a gap because the show field action is only started after the hide field action is done.

(I know I could do something similar with moving of fields behind objects with a higher layer number and use lockMoves but it is not the way i want to go for now)

Code: Select all

Hide fld "RSS_1" with visual effect push up
Show fld "RSS_2" with visual effect push up

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

Re: Execute two commands at the same time

Post by Klaus » Tue Jan 24, 2017 10:37 pm

Sorry, but we can only have one visual effect at a time.

However you could (only) "fake" a dissolve effect by setting the fields blendlevel in a repeat loop.
Know what I mean?

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

Re: Execute two commands at the same time

Post by dunbarx » Tue Jan 24, 2017 11:43 pm

How about this. Make a button and a field on a new card. Put some text into the field, maybe even a couple of lines. Size the field so you can read all. In the button script:

Code: Select all

on mouseUp
   set the topMargin of fld 1 to 25
   repeat with y = 5 to 100
      set the topMargin of fld 1 to the topMargin of fld 1 - 1
      wait 1
   end repeat
end mouseUp
You can overlay two transparent fields and run a slightly embellished handler in such a way that the text of one chases the other upwards. Just manage the margins. This can even read the contents of the fields, and determine for themselves what values to take.

Craig Newman

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 Jan 25, 2017 4:51 pm

I have to work tonight but will give it a try asap and let you know.

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

Re: Execute two commands at the same time

Post by Klaus » Wed Jan 25, 2017 5:22 pm

Dag Paul

I think this might please you:

Code: Select all

on mouseUp
   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
end mouseUp
Will do exactly what you described! :D


Groetjes

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 » Wed Jan 25, 2017 9:37 pm

Wow Klaus,
It actually does what i intended to a achieve... kudo's to you .. took some experimenting I guess :D
Thanks.

Also the solution from Craig works pretty good and has it benefits..... however it needs to run non blocking ...

Thanks guy's ......


PS. Still would like to know how to have two handlers (command A and Command B) do their thing at the same time if at all possible.. (Broadcasting ?)

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

Re: Execute two commands at the same time

Post by Klaus » Wed Jan 25, 2017 11:47 pm

mrcoollion wrote:PS. Still would like to know how to have two handlers (command A and Command B) do their thing at the same time if at all possible.. (Broadcasting ?)
Since Lc is single-threaded, this is not be possible at all.
But depending on the task, you might be able to "fake" this functionality. 8)

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

Re: Execute two commands at the same time

Post by dunbarx » Thu Jan 26, 2017 12:33 am

Hi.

Glad you have a way forward. As for blocking, simply change to "wait 1 with messages".

And as Klaus noted, since LC is single threaded, you will have to write your double handler as a single handler. but I bet with a little planning this can always be worked out.

Craig

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 » Thu Jan 26, 2017 8:23 am

Thanks .. 8)

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 » Thu Jan 26, 2017 9:27 pm

So with the knowledge gained I made a simple RSS feed ticker that really scrolls very smooth compared the way I did it previously ( delete first character of ... in a repeat loop)

Set up a field named "RSS-ticker" with following settings (you figure out why :wink: )
RSS Field settings: sharedText=false;DontWrap=true;lockText=true;opaque=true;traversalOn=false;listBehaviour=true

Put the code below in a button and run it.

Code: Select all

on mouseUp
    //===Get the RSS feed (in this case the biggest dutch news site) ======================================================================
    get url "http://www.nu.nl/rss/Algemeen"
    put it into myXML
    put revCreateXMLTree(myXML, false, true, false) into tTree
    if tTree is not an integer then
        answer "Error with revCreateXMLTree !"
        exit mouseUp
    end if
    --
    // we can directly access nodes
    put revXMLNodeContents(tTree, "rss/channel/title") && "-" && revXMLNodeContents(tTree, "rss/channel/description") into tTitleAndDescr -- this will out put sites title and description
    put tTitleAndDescr & " .... " into RSSText
    --
    put revXMLChildNames(tTree, "rss/channel/", return, "item", true) into recentPosts
    repeat for each line aPost in recentPosts
        put revXMLNodeContents(tTree, "rss/channel/" & aPost & "/title") into postTitle
        put revXMLNodeContents(tTree, "rss/channel/" & aPost & "/link") into postLink
        put postTitle & " .... " after RSSText
    end repeat
    --
    put empty into field "RSS-ticker"
    set the htmltext of field "RSS-ticker" to RSSText 
    // == Show the RSS feed text in the RSS-ticker field ==========================================================================
    put the number of characters of fld "RSS-ticker"  into tNbrOfCharacters
    // Find out the witdth of the text to stop the repeat loop after the last character.
    repeat with tCounter =1 to tNbrOfCharacters
        put the formattedWidth of Char tCounter of fld "RSS-ticker" into tCharWidth
        add tCharWidth to tTheWidth
    end repeat
    put the width of fld "RSS-ticker" into tFldWidth
    put tFldWidth into tStartLeftmargin
    put tTheWidth +tStartLeftmargin into tRepeatNumber
    set the leftMargin of fld "RSS-ticker" to tStartLeftMargin
    put "---------------------------------------------------------" after RSSText // Want to stop the ticker showing this to prove the repeat loop stops exactly where i want.
    set the htmltext of field "RSS-ticker" to RSSText 
    repeat with y = 1 to tRepeatNumber 
        set the leftMargin of fld "RSS-ticker" to the leftMargin of fld "RSS-ticker" - 1
        wait 0.5 with messages // Speed control
    end repeat
    wait 3 seconds
    set the leftMargin of fld "RSS-ticker" to 8
    //========================================================================================
end mouseUp


Thanks again......

Paul

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 » Tue Jan 31, 2017 3:26 pm

I found one issue with the Klaus solution when using

Code: Select all

lock screen for visual effect in rect (the rect of fld "RSS_1")

The problem is that during the lock screen it locks all user input in the screen and not only within the the rect of fld "RSS_1" .
Any way to solve this?

Regards,

Paul

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

Re: Execute two commands at the same time

Post by Klaus » Tue Jan 31, 2017 5:27 pm

Hi Paul,

any visual effect is completely blocking, if it happens in a rect or over the complete card!


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 » Tue Jan 31, 2017 8:59 pm

Vielen Dank Klaus,

It is good to know......

Post Reply

Return to “Talking LiveCode”