Start 2 Tasks at the same Time

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Kiliaan
Posts: 7
Joined: Mon Jan 09, 2017 6:50 pm

Start 2 Tasks at the same Time

Post by Kiliaan » Sun Jul 16, 2017 1:57 pm

Hey!
Im a beginner at Livecode and my englisch is very bad so please dont judge me. :D
I have a big Problem: Ich just want to start two methods at the same time by clicking one Button. The Problem is that when i click the Button the first method starts, but the second doesn't start.
The code just looks like that:

on Mouseup
starter1
starter2
end Mouseup

start1 and start2 are the two Methods.
I hope someone knows a good way to fix my little Problem with Livecode.
Thanks Kiliaan :)

EDIT: This is the Code the Problem occured

Code: Select all

on beginn
   go to card "game"
   put 1 into stacky
   put 0 into frager
   put 4000 into  timer
   put 4500 into timer2.1
   put 0 into score
   put score into fld "lab"
   
   wait 3 seconds

   starter1
   starter2

end beginn


###########################################################################################################
on starter1
   
   put timer-100 into timer
   put random(timer) into timer2
   if timer2<300 then
      put 300 into timer2
   end if
   wait timer2 milliseconds with messages
   set backgroundcolor of grc "g1" to "green"
   start1.1
end starter1

on start1.1
   if stacky = 1 then
      
      repeat with t = 1 to 11
         if clicker1=1 then
            
            put 0 into clicker1
            set backgroundcolor of grc "g1" to "black"
            put 0 into counter
            add 1 to score
            put score into fld "lab"
            starter1
            exit start1.1
            
            
            
         else  
            add 1 to counter2
            
            if counter2 = 10 then 
               put 0 into counter2
               put 0 into score
               put score into fld "lab"
               set backgroundcolor of grc "g1" to "red"
               wait 2 seconds 
               set backgroundcolor of grc "g1" to "black"
               put 0 into stacky
               go to card "menü"
               
               
               exit start1.1
               
            end if
         end if
         wait 120 milliseconds with messages
      end repeat
   end if
end start1.1

##########################################################################################################
on starter2
   
   put timer2.1-100 into timer2.1
   put random(timer) into timer2.2
   if timer2.2<300 then
      put 300 into timer2.2
   end if
   wait timer2.2 milliseconds with messages
   set backgroundcolor of grc "g2" to "green"
   start2.2
end starter2

on start2.2
   if stacky = 1 then
      
      repeat with t = 1 to 11
         if clicker2=1 then
            
            put 0 into clicker2
            set backgroundcolor of grc "g2" to "black"
            put 0 into counter
            add 1 to score
            put score into fld "lab"
            starter2
            exit start2.2
            
            
            
         else  
            add 1 to counter
            
            if counter = 10 then 
               put 0 into counter
               put 0 into score
               put score into fld "lab"
               set backgroundcolor of grc "g2" to "red"
               wait 2 seconds 
               set backgroundcolor of grc "g2" to "black"
               put 0 into stacky
               go to card "menü"
               
               
               exit start2.2
               
            end if
         end if
         wait 120 milliseconds with messages
      end repeat
   end if
end start2.2
Last edited by Kiliaan on Sun Jul 16, 2017 3:23 pm, edited 2 times in total.

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

Re: Start 2 Tasks at the same Time

Post by jmburnod » Sun Jul 16, 2017 2:40 pm

Hi Kiliaan,
Welcome
I think you can not start two task exactly in the same time.
I believe there is a before and an after in LiveCode.
I'm surprised that your start2 message is not sent and you haven't got an error message
if there is not a start2 message.

Create one btn and one fld in a empty cd
put this script into your btn

Code: Select all

on Mouseup
   starter1 
   starter2 
end Mouseup

on starter1
   put "starter1" && the milliseconds into line 1 of fld 1
end starter1

on starter2
   put "starter2" && the milliseconds into line 2 of fld 1
end starter2
You might use params and in this case you may do

Code: Select all

on Mouseup
   starter 1 
   starter 2 
end Mouseup

on starter pNum
   put pNum && the milliseconds into line pNum of fld 1
end starter
Best regards
Jean-Marc
https://alternatic.ch

Kiliaan
Posts: 7
Joined: Mon Jan 09, 2017 6:50 pm

Re: Start 2 Tasks at the same Time

Post by Kiliaan » Sun Jul 16, 2017 3:21 pm

Hey Thanks for your fast reply!
But unfortunately this doesnt work for my projekt, in which this problem occured.
I edited my first Question, I hope this helps to understand where my problem is.
Hope you can help me solving this problem.

Thanks, Kilian

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

Re: Start 2 Tasks at the same Time

Post by jmburnod » Sun Jul 16, 2017 3:28 pm

Hi
I see "start1.1" in your script
The correct syntax should be "start1 1"
Message and space and params separate by comma. MyMessage param1,param2 etc...

you have to declare variable on top on script like that. If not, all variables aren't empty after "end beginn"

Code: Select all

local stacky, frager, timer, timer2.1, score
on beginn
--   ...
   put 1 into stacky
   put 0 into frager
   put 4000 into  timer
   put 4500 into timer2.1
   put 0 into score
 --  ...
end beginn
Jean-Marc
https://alternatic.ch

Kiliaan
Posts: 7
Joined: Mon Jan 09, 2017 6:50 pm

Re: Start 2 Tasks at the same Time

Post by Kiliaan » Sun Jul 16, 2017 3:47 pm

Thanks for your fast Reply

I left some Parts from my code out, to show you my Problem a bit better...
I decleared all Vars correctly, and changed the Syntax like you showed me....
But anyways, the same Problem :o

But Thanks for helping me trying to fix my Problem, i appreciate this alot

Kilian

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Start 2 Tasks at the same Time

Post by MaxV » Tue Jul 25, 2017 3:51 pm

Try this:

Code: Select all

on beginn
   send   starter1 to me in 0 sec
  send    starter2 to me in 0 sec
end beginn
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Start 2 Tasks at the same Time

Post by FourthWorld » Tue Jul 25, 2017 5:22 pm

Like Python and some others, LiveCode is a single-threaded engine, so true parallelism is out. But unlike Python, LC has no explicit means of interleaving execution, so even concurrency is not LC's strong suit.

That said, there are ways to emulate concurrent style using timers and other options. This stack illustrates a few:
http://fourthworld.net/channels/lc/IdleHour.rev

If this were a desktop app you could have both concurrency and parallelism using multiprocessing as opposed to multithreading. With the ability to spawn faceless processes easily, multiprocessing can be done very effectively in LC. I haven't tried multiprocessing on Android, howerver, so I have no sense of how useful it'll be for your app (and given RAM constraints on mobile devices may not be worth the effort).

If you provide more info on the specific task you're looking to achieve we may be able to provide more specific guidance.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Start 2 Tasks at the same Time

Post by MaxV » Wed Jul 26, 2017 6:57 am

FourthWorld wrote:Like Python and some others, LiveCode is a single-threaded engine, so true parallelism is out. But unlike Python, LC has no explicit means of interleaving execution, so even concurrency is not LC's strong suit.

That said, there are ways to emulate concurrent style using timers and other options. This stack illustrates a few:
http://fourthworld.net/channels/lc/IdleHour.rev

If this were a desktop app you could have both concurrency and parallelism using multiprocessing as opposed to multithreading. With the ability to spawn faceless processes easily, multiprocessing can be done very effectively in LC. I haven't tried multiprocessing on Android, howerver, so I have no sense of how useful it'll be for your app (and given RAM constraints on mobile devices may not be worth the effort).

If you provide more info on the specific task you're looking to achieve we may be able to provide more specific guidance.
Yes, probably another solution is

Code: Select all

lock screen
.... all you code here...
unlock screen
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Android Deployment”