Underneath
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Underneath
For a variety of reasons I am trying to set up a stack for children to drag and drop letter tiles onto a grid
with predetermined locations for the tiles.
I cannot use my "normal" drag and drop scripts because children have to be able to clone letter tiles from an "alphabet bank".
So when a child clicks on a template tile in the alphabet bank which contains a script of this sort:
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to IMENA
set the script of img IMENA to fld "fscrip"
end mouseDown
So, if the child clicks on tile template "X.png" s/he ends up with a new tile called "X"
containing the script contained in field "fscrip"
So far, so good, and no rocket science either.
Now the "board' consists of a series of target tiles. Those that are NOT targets are all called "%9", and those that are targets
have names that contain only one alphabetic character; the alphabetic character of the tile that should be dragged there.
Richmond got stuck at this point.
Jeanne De Voto very kindly stepped in with the 'meat' of this:
on mouseUp
put the short name of me into IMENA
repeat with x = 1 to the number of controls
if within(control x, the mouseLoc) AND (IMENA is in the short name of control x) AND (the ID of the target is not the ID of control x) then
--do nix
else
move me to 1000,700
exit repeat
end if
end repeat
end mouseUp
BUT it doesn't work in that the tile always moves to 1000,700.
This is a sort of micro-version of my stack.
with predetermined locations for the tiles.
I cannot use my "normal" drag and drop scripts because children have to be able to clone letter tiles from an "alphabet bank".
So when a child clicks on a template tile in the alphabet bank which contains a script of this sort:
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to IMENA
set the script of img IMENA to fld "fscrip"
end mouseDown
So, if the child clicks on tile template "X.png" s/he ends up with a new tile called "X"
containing the script contained in field "fscrip"
So far, so good, and no rocket science either.
Now the "board' consists of a series of target tiles. Those that are NOT targets are all called "%9", and those that are targets
have names that contain only one alphabetic character; the alphabetic character of the tile that should be dragged there.
Richmond got stuck at this point.
Jeanne De Voto very kindly stepped in with the 'meat' of this:
on mouseUp
put the short name of me into IMENA
repeat with x = 1 to the number of controls
if within(control x, the mouseLoc) AND (IMENA is in the short name of control x) AND (the ID of the target is not the ID of control x) then
--do nix
else
move me to 1000,700
exit repeat
end if
end repeat
end mouseUp
BUT it doesn't work in that the tile always moves to 1000,700.
This is a sort of micro-version of my stack.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
A large part of the problem is that the script keeps reporting the name of the underlying
target image as "%9" even when the mouseLoc is within the target "%P2".
target image as "%9" even when the mouseLoc is within the target "%P2".
Last edited by richmond62 on Thu Nov 03, 2016 7:44 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
I had better say this before anyone else does . .
Yes, this works perfectly:
on mouseDown
grab me
end mouseDown
on mouseUp
if within(img "%P2", the mouseLoc) OR within(img "%P3", the mouseLoc) then
--nix
else
move me to 350,350
end if
end mouseUp
BUT that does NOT help much as while that would be perfectly acceptable for a series of
premade tiles, it is no good for a series of tiles cloned from templates.
Yes, this works perfectly:
on mouseDown
grab me
end mouseDown
on mouseUp
if within(img "%P2", the mouseLoc) OR within(img "%P3", the mouseLoc) then
--nix
else
move me to 350,350
end if
end mouseUp
BUT that does NOT help much as while that would be perfectly acceptable for a series of
premade tiles, it is no good for a series of tiles cloned from templates.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
If one names one's targets with various non-alphabetic prefixes this works well:
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into IMENA
if within(img ("%" & IMENA), the mouseLoc) OR within(img ("^" & IMENA), the mouseLoc) OR within(img ("#" & IMENA), the mouseLoc) then
--nix
else
move me to 350,350
end if
end mouseUp
AND, when one stops and thinks about things that's a whole lot simpler than what I was trying earlier.
If anyone is interested 'IMENA' (Имена) is Bulgarian for 'name'.
I find it is useful to name variables and fields is such a way that when I return to things later I stand a chance of
understanding what they are there for: by using a foreign language (well, not the commonly tolerated patois - English)
variables and fields are clearly labelled without those labels being reserved words.
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into IMENA
if within(img ("%" & IMENA), the mouseLoc) OR within(img ("^" & IMENA), the mouseLoc) OR within(img ("#" & IMENA), the mouseLoc) then
--nix
else
move me to 350,350
end if
end mouseUp
AND, when one stops and thinks about things that's a whole lot simpler than what I was trying earlier.
If anyone is interested 'IMENA' (Имена) is Bulgarian for 'name'.
I find it is useful to name variables and fields is such a way that when I return to things later I stand a chance of
understanding what they are there for: by using a foreign language (well, not the commonly tolerated patois - English)
variables and fields are clearly labelled without those labels being reserved words.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
Now my next problem is how to make the cloned tile vanish if it is not dumped on the target:
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into IMENA
if within(img ("%" & IMENA), the mouseLoc) OR within(img ("^" & IMENA), the mouseLoc) OR within(img ("#" & IMENA), the mouseLoc) then
--nix
else
move me to 1000,700
if intersect(img IMENA, grc "vanish") then
delete me
end if
end if
end mouseUp
that script "throws a bluey" because delete me is inside a mouseUp
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into IMENA
if within(img ("%" & IMENA), the mouseLoc) OR within(img ("^" & IMENA), the mouseLoc) OR within(img ("#" & IMENA), the mouseLoc) then
--nix
else
move me to 1000,700
if intersect(img IMENA, grc "vanish") then
delete me
end if
end if
end mouseUp
that script "throws a bluey" because delete me is inside a mouseUp
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
Here's a version of this stack with a script by Randy Hengist:
and in the context of the small stack it does work.
However it does not work in the context of my stack which has multiple targets:
Hint:
A
P
PUMPKIN
L
E
and in the context of the small stack it does work.
However it does not work in the context of my stack which has multiple targets:
Hint:
A
P
PUMPKIN
L
E
Last edited by richmond62 on Sun Aug 28, 2016 8:40 am, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
Very many people came up with helpful advice; most of which I tried, but none of which I took in the end
as it didn't work.
All I can say is Thank Goodness for my wife who dragged me out for a long walk in the fresh air!
It has taken me a far far longer time than I thought it would to iron this lot out, and looking back on it
I can see why; because of my initial "very clever" idea to have end-users cloning letter tiles from templates.
I am posting the full stack here: it's FOSS; so "steal" it, modify it, use it to teach languages, cook your trousers, whatever you want, but DON'T blame me.
Removed link as replaced by file in later posting.
This contains 2 cards: if you want to add more that's up to you.
as it didn't work.
All I can say is Thank Goodness for my wife who dragged me out for a long walk in the fresh air!
It has taken me a far far longer time than I thought it would to iron this lot out, and looking back on it
I can see why; because of my initial "very clever" idea to have end-users cloning letter tiles from templates.
I am posting the full stack here: it's FOSS; so "steal" it, modify it, use it to teach languages, cook your trousers, whatever you want, but DON'T blame me.
Removed link as replaced by file in later posting.
This contains 2 cards: if you want to add more that's up to you.
Last edited by richmond62 on Sun Aug 28, 2016 6:33 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
A further problem has arisen, as when a letter tile is clicked on it contains a script to set the script of the cloned tile:
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to IMENA
set the script of img IMENA to fld "fscrip"
end mouseDown
this throws an exception when a second or a third tile is cloned because it has the same name as an existing tile
so the engine does not "know" which of the 2 tiles called, for instance "X", it must change the script.
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to IMENA
set the script of img IMENA to fld "fscrip"
end mouseDown
this throws an exception when a second or a third tile is cloned because it has the same name as an existing tile
so the engine does not "know" which of the 2 tiles called, for instance "X", it must change the script.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
Thanks to my wife who tried the stack, I spotted a serious problem which I have now solved
with the use of a global and modified tile scripts and the script in the field "fscrip".
I also tidied up the look of the thing a bit as my wife was, rightly, critical.
Removed link as replaced by file in later posting.
with the use of a global and modified tile scripts and the script in the field "fscrip".
I also tidied up the look of the thing a bit as my wife was, rightly, critical.
Removed link as replaced by file in later posting.
Last edited by richmond62 on Tue Aug 30, 2016 9:03 am, edited 2 times in total.
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
The script inside the template letter tiles now goes like this:
[b]global[/b] TNUMB
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to (IMENA & TNUMB)
set the script of img (IMENA & TNUMB) to fld "fscrip"
add 1 to TNUMB
end mouseDown
The global TNUMB is declared and set to 1 in the cardScript,
and now sequential clones are named, for instance "X1", "X2" and so on,
so avoiding the problem that was present before.
However this also has to be accounted for in the script that is "injected" into the cloned letter tiles from the field "fscrip":
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into XIMENA
put the first char of XIMENA into IMENA
put empty into fld "targes"
if exists(img ("%" & IMENA)) then
put the short name of img ("%" & IMENA) & cr after fld "targes"
end if
if exists(img ("^" & IMENA)) then
put the short name of img ("^" & IMENA) & cr after fld "targes"
end if
if exists(img ("$" & IMENA)) then
put the short name of img ("$" & IMENA) & cr after fld "targes"
end if
if exists(img ("&" & IMENA)) then
put the short name of img ("&" & IMENA) & cr after fld "targes"
end if
if exists(img ("*" & IMENA)) then
put the short name of img ("*" & IMENA) & cr after fld "targes"
end if
if exists(img ("!" & IMENA)) then
put the short name of img ("!" & IMENA) & cr after fld "targes"
end if
if exists(img ("+" & IMENA)) then
put the short name ofimg ("+" & IMENA) & cr after fld "targes"
end if
if exists(img ("#" & IMENA)) then
put the short name of img ("#" & IMENA) & cr after fld "targes"
end if
----->>>--X--<<<-----
put the number of lines of fld "targes" into KOUNT
put 1 into KNT
put 0 into WHATNEXT
repeat until KNT > KOUNT
put line KNT of fld "targes" into BULLSEYE
if intersect(img XIMENA, img BULLSEYE) then
put 1 into WHATNEXT
end if
add 1 to KNT
end repeat
if WHATNEXT = 0 then
put the short id of this card into KARD
put the name of this stack into STAQ
put the long id of me into DIMENA
send ("delete DIMENA") to card id KARD of stack STAQ in 0 ticks
end if
end mouseUp
The coloured lines strip the first letter from the letter tile's name to use for checking against suitable targets.
Dog tired . . .
[b]global[/b] TNUMB
on mouseDown
put the short name of me into IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
delete the last char of IMENA
clone me
set the name of the last image to (IMENA & TNUMB)
set the script of img (IMENA & TNUMB) to fld "fscrip"
add 1 to TNUMB
end mouseDown
The global TNUMB is declared and set to 1 in the cardScript,
and now sequential clones are named, for instance "X1", "X2" and so on,
so avoiding the problem that was present before.
However this also has to be accounted for in the script that is "injected" into the cloned letter tiles from the field "fscrip":
on mouseDown
grab me
end mouseDown
on mouseUp
put the short name of me into XIMENA
put the first char of XIMENA into IMENA
put empty into fld "targes"
if exists(img ("%" & IMENA)) then
put the short name of img ("%" & IMENA) & cr after fld "targes"
end if
if exists(img ("^" & IMENA)) then
put the short name of img ("^" & IMENA) & cr after fld "targes"
end if
if exists(img ("$" & IMENA)) then
put the short name of img ("$" & IMENA) & cr after fld "targes"
end if
if exists(img ("&" & IMENA)) then
put the short name of img ("&" & IMENA) & cr after fld "targes"
end if
if exists(img ("*" & IMENA)) then
put the short name of img ("*" & IMENA) & cr after fld "targes"
end if
if exists(img ("!" & IMENA)) then
put the short name of img ("!" & IMENA) & cr after fld "targes"
end if
if exists(img ("+" & IMENA)) then
put the short name ofimg ("+" & IMENA) & cr after fld "targes"
end if
if exists(img ("#" & IMENA)) then
put the short name of img ("#" & IMENA) & cr after fld "targes"
end if
----->>>--X--<<<-----
put the number of lines of fld "targes" into KOUNT
put 1 into KNT
put 0 into WHATNEXT
repeat until KNT > KOUNT
put line KNT of fld "targes" into BULLSEYE
if intersect(img XIMENA, img BULLSEYE) then
put 1 into WHATNEXT
end if
add 1 to KNT
end repeat
if WHATNEXT = 0 then
put the short id of this card into KARD
put the name of this stack into STAQ
put the long id of me into DIMENA
send ("delete DIMENA") to card id KARD of stack STAQ in 0 ticks
end if
end mouseUp
The coloured lines strip the first letter from the letter tile's name to use for checking against suitable targets.
Dog tired . . .
Re: Underneath
Nice catch! I fixed the issue while messing with your stack by using long id's wherever necessary, but think I like your method better.
I've been messing around with a) cloning, and then b) immedietly grabbing the new cloned letter tile, but haven't managed to make that work.
I'm wondering if an alternate method might help.. Rather than copy a script into your cloned object, it might be possible to grab the original directly, and as part of that code, clone and place a duplicate layered underneath the one being grabbed. In this way, you click and drag rather than click, click drag. (still using your numbered method, or long id's to handle the duplicate object problem) It would require a name change, or flag to mark the grabbed tile so that grabbing the same tile again won't spawn yet another tile. (easy enough to do)
Just a thought. Might improve playability, might make it worse. I haven't tried the alternate method yet.
I've been messing around with a) cloning, and then b) immedietly grabbing the new cloned letter tile, but haven't managed to make that work.
I'm wondering if an alternate method might help.. Rather than copy a script into your cloned object, it might be possible to grab the original directly, and as part of that code, clone and place a duplicate layered underneath the one being grabbed. In this way, you click and drag rather than click, click drag. (still using your numbered method, or long id's to handle the duplicate object problem) It would require a name change, or flag to mark the grabbed tile so that grabbing the same tile again won't spawn yet another tile. (easy enough to do)
Just a thought. Might improve playability, might make it worse. I haven't tried the alternate method yet.
Re: Underneath
EDIT: Changed the line that checks for intersect to the following
Using "within" removes a little bit of odd behavior
ENDEDIT
Here, try this in your tile buttons (or just one to see what it looks like)
You'll also probably want to add code to the mousedown to track that a piece is already placed so that it can't be removed once placed, and code to make sure a slot hasn't already been filled.
Code: Select all
if the mouseloc is within the rect of img tLine then
ENDEDIT
Here, try this in your tile buttons (or just one to see what it looks like)
Code: Select all
on mouseDown
lock screen
set the itemdel to "."
-- if the .jpg still appears as part of the tile name then..
if the number of items in the short name of me is 2 then
-- clone the object
clone me
-- change the tile name. This doesn't use your numbering, just uses long id's
set the name of me to item 1 of the short name of me
-- place the cloned image into proper position
set the loc of the last img to the loc of me
-- offset the old image that will be moved to make the change more obvious
set top of me to the top of the last img -5
set the left of me to the left of the last img + 5
-- place the new image (still named with .jpg) to the layer of the old image so that it appears behind
set the layer of the last img to the layer of me
end if
-- unlock the screen to make the changes visible..
unlock screen
-- then grab the old tile
grab me
end mouseDown
on mouseUp
local targes
put the short name of me into IMENA
put the long id of me into tId
put empty into fld "targes"
-- build the targes list for comparison
put "%,^,$,&,*,!,+,#" into tMute
repeat for each item tItem in tMute
if exists(img (tItem & IMENA)) then
put short name of img (tItem & IMENA) & cr after targes
end if
end repeat
delete the last char of targes
----->>>--X--<<<-----
put 0 into WHATNEXT
-- check for intersect using the targes list
repeat for each line tLine in targes
if intersect(tId, img tLine) then
-- if there is an intersect, flag it, and snap the tile into the correct position
put 1 into WHATNEXT
set the loc of me to the loc of img tLine
end if
end repeat
if WHATNEXT = 0 then
-- if there was no match flag set, then delete the tile using its long id.
send ("delete tId") to this card in 0
end if
end mouseUp
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Underneath
Frankly those weren't bothering me . . . but now you mention them . . . the clever thing would be to remove the name of the target from the field "targes" once the target had been covered.You'll also probably want to add code to the mousedown to track that a piece is already placed so that it can't be removed once placed, and code to make sure a slot hasn't already been filled.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Underneath
Hi Richmond,
I suggest an other way without cloning (which create a new id for each clone) and use customprop (avoid change name of controls).
What changes:
1. I have builded a group "grStageBtn" with 60 btn instead 60 imgs
2. A clic on an img letter
• set customprop uMyJob of cd to "MoveLetter"
• set the icon of a btn "bMoveLetter"
• set customprop uMyletter of btn "bMoveLetter" to char 1 of the short name of img letter
• set icon of btn "bMoveLetter" to short id of img letter
3. use mousemove handler instead grab to move btn "bMoveLetter"
4. mouseup of btn "bMoveLetter" set icon of btn of grp grStageBtn under mouseloc (it seems better than intersect)
5. if customprop uMyJob of cd = empty a clic on a placed letter change customprop uMyJob of cd to "moveLetter" and allows move btn "bMoveLetter"
You can download it here:
http://alternatic.ch/jmb/Encours/CRAZY%20LETTERS001.zip
Best regards
Jean-Marc
I suggest an other way without cloning (which create a new id for each clone) and use customprop (avoid change name of controls).
What changes:
1. I have builded a group "grStageBtn" with 60 btn instead 60 imgs
2. A clic on an img letter
• set customprop uMyJob of cd to "MoveLetter"
• set the icon of a btn "bMoveLetter"
• set customprop uMyletter of btn "bMoveLetter" to char 1 of the short name of img letter
• set icon of btn "bMoveLetter" to short id of img letter
3. use mousemove handler instead grab to move btn "bMoveLetter"
4. mouseup of btn "bMoveLetter" set icon of btn of grp grStageBtn under mouseloc (it seems better than intersect)
5. if customprop uMyJob of cd = empty a clic on a placed letter change customprop uMyJob of cd to "moveLetter" and allows move btn "bMoveLetter"
You can download it here:
http://alternatic.ch/jmb/Encours/CRAZY%20LETTERS001.zip
Best regards
Jean-Marc
https://alternatic.ch