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
-
TheApexEffect
- Posts: 6
- Joined: Mon Nov 18, 2013 8:34 pm
Post
by TheApexEffect » Mon Nov 18, 2013 8:43 pm
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
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Mon Nov 18, 2013 9:18 pm
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Mon Nov 18, 2013 10:03 pm
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
https://alternatic.ch
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Nov 19, 2013 12:01 am
Simon.
Can you believe these hyper-helpful people?
Craig
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Tue Nov 19, 2013 12:10 am
Hi Craig,
I think J-M didn't realize I knew the answer, well I'm hoping that's it.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Nov 19, 2013 1:35 am
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
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Nov 19, 2013 7:48 am
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.
-
[-hh]
- VIP Livecode Opensource Backer

- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
Post
by [-hh] » Tue Nov 19, 2013 9:34 am
..........
Last edited by
[-hh] on Wed Aug 13, 2014 11:51 am, edited 1 time in total.
shiftLock happens
-
TheApexEffect
- Posts: 6
- Joined: Mon Nov 18, 2013 8:34 pm
Post
by TheApexEffect » Tue Nov 19, 2013 11:04 am
Thanks for all your help, both methods were equally helpful
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Nov 19, 2013 2:50 pm
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