Two quick questions

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
Josh
Posts: 46
Joined: Sat Jan 12, 2008 6:42 am

Two quick questions

Post by Josh » Sun Jan 20, 2008 11:22 am

The first is painfully easy. What characters do I insert to continue code onto the next line when a line gets too long? I think it's something with the backslash or forward slash, but I can't figure it out or find the answer in Dan's book (though I know it's in there somewhere).

Second, I have a large array of squares that I randomly reassign to new location with every ENTER keypress. I have the squares move with the move command. It works very well, but I need the squares to not overlap. How do I repeat the move code until there is no overlap? Is that possible?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sun Jan 20, 2008 1:10 pm

1. It's the backslash: \

2. You need to code that behaviour yourself. As you are using rectangles, you can use the intersect function to determine overlaps.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Josh
Posts: 46
Joined: Sat Jan 12, 2008 6:42 am

Yes, intersect

Post by Josh » Mon Jan 21, 2008 4:33 am

I've tried used that along inside of a repeat loop (e.g., repeat move until no collision) but the code makes it choke each time. I've gone back to the drawing board, but the code did look something like this:

repeat until (collision = false)
put random () into newlocX
put random() into newlocY
move rectangle of cd to newlocx,newlocy
if intersect (rectangle,rectangle) then (collision = true).

One problem I foresee even if I got Revolution to accept the code is that, with 15 rectangles on screen, collisions are inevitable en route. I don't care if rectangles pass through one another as long as their terminal location is a nonoverlapping one. Any additional thoughts? Do I need a background of 0's that turn to 1's with a rectangle overlap. Then, only permit a move if the terminal spot is all 0's? Would anyone know how to code that if that's my only option?

P.S., Thanks for the /, sheesh what a turkey I am!

Josh
Posts: 46
Joined: Sat Jan 12, 2008 6:42 am

Solved

Post by Josh » Mon Jan 21, 2008 11:45 pm

Hi,

Thanks for the help. I've figured it out. For public record, intersect is only concerned with the terminal location to begin with (good for me, additional difficulty for those hoping for "contact" in motion). I used a collision and grandcollision boolean to set it up.

collision and grandcollision became true if contact was made
collision set to false if contact not made
if grandcollision was false after all object moved, then repeat loop ends.

Post Reply