Help with putting specific text in specific places in a button

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

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Help with putting specific text in specific places in a button

Post by Opaquer » Wed Jan 22, 2020 11:36 am

Hey guys!

So, I'm making progress with my Sudoku app (which is super exciting!), and I'm not up to the hard part - putting in numbers. I want to have the ability to put numbers into cells, but also put in pencil markings (like this sort of thing: https://imgur.com/Df8SnO5). There's two types of pencil markings here - the ones in the corners/edges of the cell (1, 2, 3, 4, 5, 6) and the centre markings (7, 8, 9). I want to be able to put both types of markings into my app

To put it into some background though, I'm making this app for Android, and the way I have it set up now is that there's a 9x9 set of buttons in my stack. When you move the mouse over one (or in this case, your finger), it will highlight it. Tapping also lets you highlight the buttons. I have a way to make the cells put numbers in, but I don't know how I can make the text of the button be that specific when it comes to the position of the numbers? Does anyone have any recommendations on how to do it?

Thanks in advanced!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 12:50 pm

Df8SnO5.png
Df8SnO5.png (723 Bytes) Viewed 7498 times
-
I uploaded your image here to help us all have a think about things.

Although, to be honest, I'm not sure what you mean about 'pencil markings.'

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Help with putting specific text in specific places in a button

Post by Opaquer » Wed Jan 22, 2020 12:55 pm

Thanks richmond - that makes it easier to see!

So, with Sudoku, a common technique is to 'pencil mark' the squares where you think numbers could be - this helps you keep track of what can and can't go in places. Depending on a few things (preference, style of solving etc), some people will put their pencil marks along the corners/edges of the cells (like the 1, 2, 3, 4, 5 and 6 in the picture), some will put it in the centre (like the 7, 8 or 9), and some will use both. I'm trying to make something that will work for all sorts of sudoku solvers :)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 1:04 pm

Well . . . here's a thought, which might be daft, but might work . . . 8)
-
S1.png
-
My mother (89 years young) does the Sudoko thing in her newspaper every day: keeps her sharp as a new pin.

Could never understand the attraction myself . . .
----
Have a group consisting of 7 fields (I have called them f1 to f7).

Of course you can set the borders of the fields to 0, and then set the border of the group to,
say, 2, so you end up with what looks like a single field.
Attachments
Sooodoko.livecode.zip
Here's the stack.
(1021 Bytes) Downloaded 209 times

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Help with putting specific text in specific places in a button

Post by Opaquer » Wed Jan 22, 2020 3:14 pm

Hi richmond

Thanks for the reply - it's not a bad idea! The only issue though is that sometimes pencil markings can be more than 6 digits, though that's pretty rare in my case.

The only other issue is that at the moment I've got it set up so that on mouse move, it checks for the name of the control under the mouse. If there's a group of fields in the way, then I won't have any way to track which cell the user is hovering over?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 3:41 pm

Have a bash with this:
-
S2.png
Attachments
Sooodoko 2.livecode.zip
Here's the stack.
(1.24 KiB) Downloaded 214 times

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Help with putting specific text in specific places in a button

Post by Opaquer » Wed Jan 22, 2020 3:51 pm

Hi richmond

That's a great idea! At the moment I have it based on mouse move with it checking the control beneath it to see if it's a valid control to do things with, but if I use mouse enter, that'll make it so much easier! And I could make a group with labels as you suggested, and then just use mouse enter on the groups?

I'll give it a shot tomorrow and see how it goes - hopefully it'll go well though!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Help with putting specific text in specific places in a button

Post by dunbarx » Wed Jan 22, 2020 4:28 pm

I would use "the target" instead of "me" when trying to see what control the cursor enters.

"Me" don't enter into it.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 4:29 pm

I would use "the target" instead of "me" when trying to see what control the cursor enters.
Can you explain why?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Help with putting specific text in specific places in a button

Post by dunbarx » Wed Jan 22, 2020 4:45 pm

Richmond.

Sure.

Make a button and a field on a new card. In the card script:

Code: Select all

on mouseEnter
 --  put the name of me into fld 1
    put the name of the target into fld 1
end mouseEnter
Try both. "Me" don't enter into it.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 5:02 pm

I must be missing something as both

Code: Select all

put the short name of me into fld "f1"
and

Code: Select all

put the short name of the target into fld "f1"
work equally well for me.
-
Me.png
Attachments
Me.livecode.zip
Here's the stack.
(975 Bytes) Downloaded 205 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Help with putting specific text in specific places in a button

Post by dunbarx » Wed Jan 22, 2020 5:33 pm

Hmmm.

In a "mouseEnter" handler? I do not see this at all.

I have a card with two fields and a button on it. In field 1 I have "XYZ". I set the contents of the button to "B1". In the card script:

Code: Select all

on mouseEnter
   if the optionKey is down then put the target into fld 2
   if the commandKey is down then put me into fld 2
   if the shiftKey is down then put  the value of  the target into fld 2
   if the controlKey is down then put target into fld 2
end mouseEnter
What do you see when you navigate into each control with each controlKey held down? I get only a card reference with the commandKey, the only line that calls for "me". This is because a card is not a container, and will yield its name.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 5:55 pm

Hmm . . . a right pain in the bum, frankly:-
-
Me2.png
-
On a Macintosh

SHIFT empties the field

CONTROL
puts the name into the field

ALT
puts the name into the field

COMMAND
empties the field

but, then, your script is inconsistent:

Code: Select all

on mouseEnter
   if the optionKey is down then put the target into fld 2
   if the commandKey is down then put me into fld 2
   if the shiftKey is down then put  the value of  the target into fld 2
   if the controlKey is down then put target into fld 2
end mouseEnter
Attachments
Me too.livecode.zip
Here's the stack.
(1.08 KiB) Downloaded 212 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Help with putting specific text in specific places in a button

Post by richmond62 » Wed Jan 22, 2020 5:59 pm

So . . . 8)
-
HW.png
-
I now have 2 buttons: "Where's the beer?" and "Where's the cheese?"
with these scripts respectively:

Code: Select all

on mouseEnter
   if the optionKey is down then put the target into fld "f1"
   if the commandKey is down then put the target into fld "f1"
   if the shiftKey is down then put the target into fld "f1"
   if the controlKey is down then put the target into fld "f1"
end mouseEnter

Code: Select all

on mouseEnter
   if the optionKey is down then put the name of me into fld "f1"
   if the commandKey is down then put the name of me into fld "f1"
   if the shiftKey is down then put the name of me into fld "f1"
   if the controlKey is down then put the the name of me into fld "f1"
end mouseEnter
and everything works . . . . :D
Attachments
Harvey Weinstein.livecode.zip
Here's the stack.
(1.17 KiB) Downloaded 205 times

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1232
Joined: Thu Apr 11, 2013 11:27 am

Re: Help with putting specific text in specific places in a button

Post by LCMark » Wed Jan 22, 2020 7:35 pm

@richmond62: That's because you have attached those scripts to the button - buttons cannot contain controls so 'the target' is always the same as 'me'. You will see a difference if you put the scripts in an object containing the button (e.g. card, or group if the button is in a group). Then 'the target' will be the button, whereas 'me' will be the object you attached the script to. [ 'the target' is the control which received the event, even if the message passes up the owner-chain; 'me' is the control whose script contains the running handler. ]

Post Reply