a creative way to crash Rev - any suggestions?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
synaptic
Posts: 11
Joined: Thu Jun 04, 2009 10:47 pm

a creative way to crash Rev - any suggestions?

Post by synaptic » Fri Aug 21, 2009 8:26 pm

So, what I'm trying to do is get two images to "line up" with points to which they are going to move. I have written this script, but all it does is close down Rev. Any suggestions for what might be wrong?

on mouseup

set the lockmoves to true
put random(1000),random(1000) into LOC1
put random(1000),random(1000) into LOC2
create image "alignment"
choose line tool
drag from loc of image "rat.gif" to LOC1
put angle of image "alignment" into NewAngle
create image "alignment2"
choose line tool
drag from loc of image "rat2.gif" to LOC2
put angle of image "alignment2" into NewAngle2

set angle of image "rat.gif" to NewAngle
set angle of image "rat2.gif" to NewAngle2
move image "rat.gif" to LOC1 without waiting
move image "rat2.gif" to LOC2 without waiting


set the lockmoves to false

end mouseup

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Fri Aug 21, 2009 9:34 pm

Synaptic,

from your code I gather that you want to move 2 images (rat.gif and rat2.gif) along a straight line and the angle of the images should be of the angle of the lines. Is that right?

In your code you make two images alignment and alignment2 that you want to have a straight line in them and then get a angle of that line by asking for the angle of image alignment.
The angle of the images alignment are alway zero since you dont change that angle, the fact that you try to draw a line has nothing to do with the angle of the images.
And you dont paint into the images since choosing the line tool and dragging from the the loc of image rat/rat2 these get a little painted on and thats it. the alignment images you created are in the center of the stack and with each iteration of your script you create 2 new alignment images (look at it in the inspector)
I tried your script by creating 2 "normal" images from the toolbar and naming them "rat.gif" and "rat2.gif". My stack did not crash. I dont know what would have happened if I would have used actual gifs.

If you want to find out the angle of the line from the loc of rat to the random loc you have to calculate the angle with a little help from Mr. Pythagoras. Then you can adjust the angle of your rats and move them, no need for the alignment images.

try this:

Code: Select all

on mouseUp
   put random(1000),random(1000) into LOC1 
   put random(1000),random(1000) into LOC2 
   put theAngle (the loc of image "rat.gif", LOC1) into NewAngle
   put theAngle (the loc of image "rat2.gif", LOC2) into NewAngle2
   
   set angle of image "rat.gif" to NewAngle 
   set angle of image "rat2.gif" to NewAngle2 
   
   set the lockmoves to true
   move image "rat.gif" to LOC1 without waiting 
   move image "rat2.gif" to LOC2 without waiting 
   set the lockmoves to false 
end mouseUp

function theAngle tPoint1, tPoint2
   -- find absolute angle
   put item 1 of tPoint1 into x1
   put item 2 of tPoint1 into y1
   put item 1 of tPoint2 into x2
   put item 2 of tPoint2 into y2
   put x1-x2 into oppositeLeg
   put y1-y2 into adjacentLeg
   put round (abs(atan2(adjacentLeg,oppositeleg)*180/pi-180)) into tNewAbsoluteAngle
   return tNewAbsoluteAngle
end theAngle
but it gives you the absolute angle, this might not be what you want (from 0 to 360 degrees) You might have to adjust that to your needs.

regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sat Aug 22, 2009 12:13 am

Synaptic,
if you want your images to return to an angle of zero degree after the movement you could put this code into the script of the animated images:

Code: Select all

local tMyAngle
on movestopped
   put the angle of me into tmyAngle
   send turnMetoZero to me
end movestopped

on turnMetoZero
   if tMyAngle > 0 then
      put tMyAngle - 5 into tMyAngle
      set the angle of me to tMyAngle
      send turnMetoZero to me in 5 milliseconds
   else
      set the angle of me to 0
   end if
end turnMetoZero
if you dont want the animation you could just say:

Code: Select all

on movestopped
   set the angle of me to 0
end movestopped
note that the first piece of code uses a send in time construct that gives Revolution time enough to refresh the screen. It is much preferable to a repeat loop in this case. Send in time calls itself until a condition is met, in this case tMyAngle is not greater then 0, in that case the angle is set to 0 (could have been a negative number) and than turnMetoZero is not called again.
regards
Bernd

synaptic
Posts: 11
Joined: Thu Jun 04, 2009 10:47 pm

Post by synaptic » Sat Aug 22, 2009 12:15 am

Thanks! This is very helpful...

Post Reply