I have asked about the intersect command before and got a bunch of help (thanks so much sefrojones).  But I am having trouble with it still on a different card.  On most of my game a hand comes down from the top and tries to grab a phone on the bottom of the screen.  If the user moves the hand out of the way a point is added and when they get 5 pts they move to the next level.  If there is a collision between the grabbing hand and the phone then they lose and go to the last screen.
In this level it is a rapid fire round.  they keep amassing points until they lose.  trouble is the intersect works on all the other cards but not this one.  I have rewritten the code, copied working cards and modified them and still can't make it work.
If the user moves and the intersect occurs the collision is detected.  If the user does not move the phone and an intersect occurs the collision is NOT detected.  I can leave the phone in one place and the collision is never detected and the loop continues forever.
If anyone could help I would appreciate it.  
=====================================================================
Local sGrabbing
Local sTime1
Local sTime2
global gFScore
on preOpenCard
   global gname  
   put 0 into field "finalscore" of last card
   show field "ptsneeded"
   hide image "funbegins.gif"
   hide image "3.gif"
   hide image "2.gif"
   hide image "1.gif"  
   put 30 into field "score"
   put true into sGrabbing
   put "3" into sTime1
   put "3.1" into sTime2
   set the sRunning of this cd to true
   set the location of image "rthand1.gif" to -37, -303
   set the location of image "lfthand2.gif" to 770, -309
   set the location of image "phone.gif" to 320, 509
   set the sRunning of this cd to "true"
   confiscated
end preOpenCard
on arrowkey pDirection
   movephone pDirection
   hide field "ptsneeded"
end arrowkey
command confiscated
   if intersect(image"rthand1.gif",image"phone.gif","pixels")
      then go to last card
      else if intersect(image"lfthand2.gif",image"phone.gif","pixels")
      then go to last card
      if the sRunning of this cd is true then send confiscated to me in 2 ticks
end confiscated
command movephone pDirection
   if pDirection is "right" then
      set the right of image "phone.gif" to the right of image "phone.gif" +60
          if right of the image "phone.gif" >800 then
         set the right of image "phone.gif" to 800
         end if
           
         else if pDirection is "left" then
            set the left of image "phone.gif" to the left of image "phone.gif" -60 
             if left of the image "phone.gif" <-120 then
         set the left of image "phone.gif" to -120
         end if        
      end if 
      end movephone
On moveobj
   if sGrabbing then
   put random(2) into vHand
   if vHand is 1 then
   move image ("rthand1.gif") to the points of graphic ("rtPath"&random(2)) in sTime1 second
      else
      move image ("lfthand2.gif") to the points of graphic ("lftPath"&random(2)) in sTime1 second
   end if   
send "moveobj" to me in sTime2 seconds
add 1 to field "score"
add -.2 to sTime1
add -.2 to sTime2
end if 
set the sRunning of this cd to false
end moveobj
on closecard 
   set the sRunning of this cd to false
   add field "score" to field "finalscore" of last card
end closecard
			
			
									
									
						Intersect - Again
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
- 
				sefrojones
- Livecode Opensource Backer 
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Intersect - Again
It looks like the if/then statements are not set up properly in your "confiscated" handler. Maybe something like this will work:
			
			
									
									
						Code: Select all
command confiscated
   if intersect(image"rthand1.gif",image"phone.gif","pixels") then 
      go to last card
      exit confiscated
   end if
   
      if intersect(image"lfthand2.gif",image"phone.gif","pixels") then 
         go to last card
         exit confiscated
      end if
      
      if the sRunning of this cd is true then send confiscated to me in 2 ticks
End Confiscated
Re: Intersect - Again
Your if then statements are a bit mangled with missing end if closures but I think the problem may be that in every iteration of the moveobj handler you set the sRunning to false, so the confiscated handler will not then iterate again.
			
			
									
									
						- 
				Peacfulrvr
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: Intersect - Again
Thanks I will see if that helps
			
			
									
									
						- 
				Peacfulrvr
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: Intersect - Again (solved)
Excellent!  Thanks so much.  I cleaned up the if/then statements and removed the extra "set the sRunning of this cd to false" and is works now.