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!
on mouseDown
grab me
end mouseDown
on mouseUp
put 1 into TARGE
repeat until TARGE > 16
put ("t" & TARGE) into DEST
if not within (img DEST, the mouseLoc) then
-- do nix
else
set the loc of img "pawn" to the loc of img DEST
end if
add 1 to TARGE
end repeat
end mouseUp
Last edited by richmond62 on Wed Apr 08, 2020 8:34 am, edited 1 time in total.
on mouseDown
grab me
end mouseDown
on mouseUp
put 1 into TARGE
repeat until TARGE > 16
put ("t" & TARGE) into DEST
if not within (img DEST, the mouseLoc) then
-- do nix
else
set the loc of img "pawn" to the loc of img DEST
put the loc of img DEST into LOQ --XXX--
end if
add 1 to TARGE
end repeat
if the loc of img "pawn2" is LOQ then --XXX--
put random(16) into RNX
put ("t" & RNX) into TRGT
set the loc of img "pawn2" to the loc of img TRGT
end if --XXX--
end mouseUp
Thank you, Richmond. That's pretty much what I've done as well except I used intersect instead of within. Is there good reason to choose one over the other in this instance?
Well, intersect seems to work quite well in my chess game, so what gives?? here's my script:
on determineSquare
repeat with j = 1 to 64
if the intersect(the target, grc j of grp ChessboardArray) then
set the loc of the target to the loc of grc j of grp chessboardArray
put the short name of grc j of grp chessboardArray
end if
end repeat
end determineSquare
If you drop [i.e. mouseUp] your chess piece in a position where it intersects with 4 squares, how are you going to work out
on which of those 4 squares it is going to end up?
-
It doesn't even have to get as complicated as 4 squares, 2 would have been sufficient heh. If your halfway between 1 and the other, your intersecting both, which loc does your piece go to?
The main difference is, as I said before, 'within rect' makes sure you don't have to worry about it. You personally aren't going to drop it halfway, but I guarantee if you have enough testers, or worse, end users, one of them will just to mess with you.
. . . remember the useful 'fact' that at least 50% of people are stupid (i.e. the other side of the IQ bell curve to Thee and Me) . . .
Now, knowing this, and the fact that I [if you really want to believe what is fairly tendentious crap] have an IQ of 142, I always plan
for the chap (or chappess) who has an IQ of 58 . . .
I understand what you and Bogs are saying and I'm not against using "within" instead of "intersect", but my script is really working quite well...at least the chess game is working the way I think it should work. Nevertheless, I'll give "within" a try and see if I like it better.