two Loops at the same time

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
Bellyfay
Posts: 2
Joined: Thu Apr 28, 2016 11:41 am

two Loops at the same time

Post by Bellyfay » Thu Apr 28, 2016 11:54 am

Hello everybody,

I have to write a program, presenting visual and auditive information. The problem is, that both types need their own loop which need to be started at the same time. Is there any command to run two loops parallel?

I'm a complete beginner in working with LiveCode, so I hope anybody can answer my question.

Thanks,

Dunja

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: two Loops at the same time

Post by Klaus » Thu Apr 28, 2016 12:28 pm

Hi Dunja,

1. welcome to the forum! :D
2. can you tell us a bit more? Do you mean "repeat" loops?
I'm not sure I understand what exactly you are after...


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: two Loops at the same time

Post by dunbarx » Thu Apr 28, 2016 1:53 pm

Hi.

What Klaus said.

LC can indeed run more than one loop simultaneously, provided you (and we) know what is required.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: two Loops at the same time

Post by FourthWorld » Thu Apr 28, 2016 3:30 pm

Like Python, LC is single-threaded and doesn't support concurrency. But although Python has more explicit support for parallelism than LC, some useful forms of parallelism can be achieved in LC quite easily with timers. This example stack shows a few different methods for parallel loop processing:
http://fourthworld.net/channels/lc/IdleHour.rev
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Bellyfay
Posts: 2
Joined: Thu Apr 28, 2016 11:41 am

Re: two Loops at the same time

Post by Bellyfay » Mon May 02, 2016 8:41 am

Thanks for answering. I hope this helps you to understand what I mean:

I want to program an experiment with several trials. Every trial shall look like this:

The program shall present a sequence of sounds in which every single sound shall be presented one second after the first one. The order of sounds has to be randomized.
At the same time, a sequence of visual stimuli (like pictures or letters) shall be presented with 500ms between each stimulus (randomized order).

The duration of the auditive sequence is longer than the duration of the visual sequence.


The problem I have is that I have written one loop for the auditive sequence and one for the visual one. LC reads the code from top to bottom, so it presents both sequences in a row.
I would like to start both loops simultaneously.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: two Loops at the same time

Post by dunbarx » Mon May 02, 2016 3:08 pm

Hi.

To help me understand, how does the 1 second interval between successive sounds map with the half-second interval of the images? These will get out of sync after the first pair is shown and heard. I see you are aware of this, but how would the user see the process, er, proceed?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: two Loops at the same time

Post by dunbarx » Mon May 02, 2016 3:22 pm

Try this.

Make a button and two fields. In the button script:

Code: Select all

on mouseUp
   put the ticks into tStart
   put 1 into x
   repeat with y = 1 to 10
      put "Sound" && y into fld 1
       put "Image" && x into fld 2
      wait 30
     add 1 to x
     put "Image" && x into fld 2
       add 1 to x
   end repeat
end mouseUp
Now this is a brute-force method of nesting two processes within a single loop. Whether this does what you need, or is robust enough, is another story. which you must come back and say.

Craig

Post Reply