Page 1 of 1

Creating generation at a set time period

Posted: Mon Nov 18, 2013 8:43 pm
by TheApexEffect
I'm currently having a slight problem with a program I am creating. I need to get a random image to appear every 15 seconds but I don't know the code to get the generation to occur at the time intervals. I'm coding it on a mac and this is what I have so far.

Code: Select all

on randomgenerate
   put random(3) into appearance 
   put random (3) into position
   if appearance = 1 then
      set the filename of image "Enemy" to "cartoon_shark.gif"
   end if
   
   if appearance = 2 then
      set the filename of image "Enemy" to "Coral.jpg"
   end if
   
   if appearance = 3 then
      set the filename of image "Enemy" to "Cartoon-Scuba-Diver-Hug.jpg"
   end if
   
     if position = 1 then
      set the loc of image "Enemy" to 400,random(500)
   end if
   
   if position = 2 then
      set the loc of image "Enemy" to 400, random(650)
   end if
   
   if position = 3 then
      set the loc of image "Enemy" to 400, random(500)
   end if
   
     if the right of image("Enemy") < the right of this card then
      set the right of image("Enemy") to the right of this card
   end if
    if the left of image("Enemy") < the left of this card then
      set the left of image("Enemy") to the left of this card
   end if
   movement
end randomgenerate

on movement
   put item 2 of loc of image "Enemy" into tY
   move image "Enemy" to -50,tY in 10 seconds
end movement
This is the code for both generating the images and making them move. Any help on how to get the movement to occur after each time interval.

Thanks in advance for any help offered

Re: Creating generation at a set time period

Posted: Mon Nov 18, 2013 9:18 pm
by Simon
Hi TheApexEffect,
Welcome to the forums!

Have you worked with "send" yet?
It can be used to "send" a command at a particular time interval. In this case you'd want to "send" randomgenerate at a set time.

Now the challenge here is where do you place it?

Simon

Re: Creating generation at a set time period

Posted: Mon Nov 18, 2013 10:03 pm
by jmburnod
Hi ,

As Simon said you can use a send in time message.

Code: Select all

on startRandomgenerate
   Randomgenerate
end startRandomgenerate

on randomgenerate
  --Your script lines

   if "randomgenerate" is not in the pendingmessages then
      send "randomgenerate" to me in 15 seconds
   end if
end randomgenerate

on stopRandomgenerate
   doStopPending randomgenerate
end stopRandomgenerate

on doStopPending pMessage
   repeat for each line aLine in the pendingmessages
      if pMessage is in item 1 of tLine then
         cancel item 1 of aLine
      end if
   end repeat
end doStopPending
No tested but it should work

Best
Jean-Marc

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 12:01 am
by dunbarx
Simon.

Can you believe these hyper-helpful people?

Craig

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 12:10 am
by Simon
Hi Craig,
I think J-M didn't realize I knew the answer, well I'm hoping that's it.

Simon

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 1:35 am
by dunbarx
Hmmm.
I think J-M didn't realize I knew the answer, well I'm hoping that's it.
Let's see... Simon... Hmmm... 1600+ posts, covering all aspects of LC. Hmmm...

I think he just is what I said. Very helpful. He just isn't our kind of mentor.

Craig

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 7:48 am
by SparkOut
Hijacking for a second, I don't see there's always a problem with just giving a straight answer with code. A clearly commented code sample can help the penny drop and have the idea sink in just as easily and with less stumbling on the way, in some cases. I don't think it is a good idea to spoonfeed everyone coming with a question, but I don't see that people should be shy of contributing with code examples either.

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 9:34 am
by [-hh]
..........

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 11:04 am
by TheApexEffect
Thanks for all your help, both methods were equally helpful

Re: Creating generation at a set time period

Posted: Tue Nov 19, 2013 2:50 pm
by dunbarx
Well.

This is just a sort of private joke between Simon and I, who have never met, started a couple of years ago, and is of little consequence. All that really matters is that the help given here, of whatever style, and whether that style best addresses the needs of the "student", derives from a passion for LC. This has always been a source of wonder to me, dating back to the Hypercard forums of two decades ago, which had the very same flavor, and, amazingly, many of the same participants.

This last was just another opportunity to mention HC, so we never forget our roots.

Craig