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!
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.
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.
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!
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
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.
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.