Simplify this?
Posted: Sat Oct 18, 2008 7:14 pm
Hi all,
Compiles for debugging are taking forever because of my code. Can any show me how to shorten/tighten this up? It basically involves 14 (or 15) green squares presented in random positions onscreen with 1 (or none) red square (the "target"). I bet a function would work, but I don't know how to do that or if that is the best route. Thanks for any help.
---
if targetTrial is true then
put true into collision
repeat until collision=false
put false into grandcollision
put 0 into newlocx
put 0 into newlocy
repeat until ((newlocx > 50+item 1 of windowBoundingRect) and (newlocx < item 3 of windowboundingrect - 50) and \
(newlocy > 50 + item 2 of windowBoundingRect) and (newlocy < item 4 of windowboundingrect - 50))
put 50 + random(item 3 of windowboundingrect - 50) into newlocx
put 50 + random(item 4 of windowboundingrect - 50) into newlocy
end repeat
move grc "targetrectangle" of card "practicesearch" of stack "metavssetsize" to newlocx,newlocy in 1 millisec
if intersect(grc "targetrectangle", grc "rectangle1") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle2") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle3") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle4") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle5") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle6") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle7") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle8") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle9") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle10") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle11") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle12") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle13") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle14") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if grandcollision then put true into collision
end repeat
end if
Compiles for debugging are taking forever because of my code. Can any show me how to shorten/tighten this up? It basically involves 14 (or 15) green squares presented in random positions onscreen with 1 (or none) red square (the "target"). I bet a function would work, but I don't know how to do that or if that is the best route. Thanks for any help.
---
if targetTrial is true then
put true into collision
repeat until collision=false
put false into grandcollision
put 0 into newlocx
put 0 into newlocy
repeat until ((newlocx > 50+item 1 of windowBoundingRect) and (newlocx < item 3 of windowboundingrect - 50) and \
(newlocy > 50 + item 2 of windowBoundingRect) and (newlocy < item 4 of windowboundingrect - 50))
put 50 + random(item 3 of windowboundingrect - 50) into newlocx
put 50 + random(item 4 of windowboundingrect - 50) into newlocy
end repeat
move grc "targetrectangle" of card "practicesearch" of stack "metavssetsize" to newlocx,newlocy in 1 millisec
if intersect(grc "targetrectangle", grc "rectangle1") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle2") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle3") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle4") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle5") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle6") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle7") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle8") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle9") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle10") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle11") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle12") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle13") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if intersect(grc "targetrectangle", grc "rectangle14") then
put true into collision
put true into grandcollision
else
put false into collision
end if
if grandcollision then put true into collision
end repeat
end if