two Loops at the same time
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
two Loops at the same time
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
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
Re: two Loops at the same time
Hi Dunja,
1. welcome to the forum!
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
1. welcome to the forum!

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
Re: two Loops at the same time
Hi.
What Klaus said.
LC can indeed run more than one loop simultaneously, provided you (and we) know what is required.
Craig Newman
What Klaus said.
LC can indeed run more than one loop simultaneously, provided you (and we) know what is required.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: two Loops at the same time
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
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: two Loops at the same time
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.
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.
Re: two Loops at the same time
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
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
Re: two Loops at the same time
Try this.
Make a button and two fields. In the button script:
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
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
Craig