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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 08, 2020 7:25 am
Yes, I did mean to spell "bored" in that way.
-
-
Script in "pawn":
Code: Select all
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.
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 08, 2020 8:33 am
Last edited by
richmond62 on Wed Apr 08, 2020 9:30 am, edited 1 time in total.
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 08, 2020 9:29 am
-
Code: Select all
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
Changes in code are marked with "--XXX--"
-
Attachments
-
- drop targetter.livecode.zip
- Here's the stack.
- (13.32 KiB) Downloaded 269 times
-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Wed Apr 08, 2020 3:21 pm
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?
Roger
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Wed Apr 08, 2020 3:25 pm
If you mean where you want the graphic to sit inside one of the squares of the board, then yes, within the rect would be the best choice.
Intersect just tells you if any part of one is crossing a line of the other.
-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Wed Apr 08, 2020 6:16 pm
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
Roger
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 08, 2020 6:30 pm
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?
-

- board.png (16.09 KiB) Viewed 9664 times
-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Wed Apr 08, 2020 7:58 pm
I'm not going to drop it on a corner. I'm going to drop it mostly in one square or another....it's working flawlessly!!
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Wed Apr 08, 2020 8:02 pm
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.
-
richmond62
- Livecode Opensource Backer

- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Apr 08, 2020 8:18 pm
Roger . . .
. . . 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 . . .
-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Wed Apr 08, 2020 8:30 pm
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.
Thanks,
Roger
-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Wed Apr 08, 2020 8:36 pm
I concede!! What I failed to notice was that you all were using the mouseLoc "within" a square which is clearly better, and I like it better!
Thanks for your help!
Roger
-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Wed Apr 08, 2020 8:44 pm
RogGuay wrote: ↑Wed Apr 08, 2020 8:36 pm
I concede!!
Wow, Richmond, I've seen some pretty quick conversions in my time, but I think you took the cake with Roger there

-
RogGuay
- VIP Livecode Opensource Backer

- Posts: 122
- Joined: Fri Apr 28, 2006 12:10 am
Post
by RogGuay » Thu Apr 09, 2020 12:36 am
Bogs, you deserve equal credit.