Getting around simultaneous repeat loops

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
susan08
Posts: 2
Joined: Fri Oct 03, 2008 3:12 am

Getting around simultaneous repeat loops

Post by susan08 » Fri Oct 03, 2008 3:25 am

Hi,

I am trying to find an alternative to running simultaneous repeat loops (which is what I want to do, but isn't possible.)

The program displays images and plays audio files for an experiment.

The images are displayed according to certain timing (random within restrictions)- this is currently working within a repeat loop.

The problem is that a set number of tones need to occur randomly throughout the duration of the program, without affecting the presentation of the images. I currently have this set up as another repeat loop which checks every 1s whether a tone should be played, but I cannot have the two repeat loops operating at once.
eg:
repeat until all tones are played
check if a tone needs to be played now
if yes, play tone, end if
wait for 1 second with messages
end repeat

Any comments or suggestions on logic to get around this would be appreciated. thanks.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 03, 2008 3:36 am

Hi Susan,

You can use the send command to execute handlers simultaneously. Your script would look more or less like this.

Code: Select all

on showPics
  repeat with x = 1 to number of images
    hide img x
  end repeat
  show img random(number of images)
  send showPics to me in random(10) secs
end showPics

on playSounds
  repeat with x = 1 to number of images
    if the visible of img x then exit repeat
  end repeat
  play "Sound" && x & ".wav" -- file path!
  send playSounds to me in random(10) secs
end playSounds
This script would play a sound depending on which picture is visible. I am sure you want something completely differently, as I don't know which tones should be played when, but this might give you some ideas.

Best,

Mark
Last edited by Mark on Fri Oct 03, 2008 9:24 am, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

susan08
Posts: 2
Joined: Fri Oct 03, 2008 3:12 am

Post by susan08 » Fri Oct 03, 2008 3:49 am

Hi Mark,

Thank you for the prompt reply. That was very helpful!

The send command might be exactly what I need.

In my program, a white square is displayed on the screen according to a pseudo random timing schedule, and the tones should play 100 times randomly throughout that schedule (i.e. independent of whether the square is currently visible or not).

I'll try and get it working now.

many thanks,

Susan

Post Reply