[Newbie Question] hilite of button 1 group 1 -- help please

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

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

[Newbie Question] hilite of button 1 group 1 -- help please

Post by shawnblc » Thu Jul 24, 2014 1:31 pm

Here's my code. What I'm trying to do is if the check box is checked then at least one in the group needs checked.

Code: Select all

      if the hilite of btn "1" is true and the hilite of group "group1" is false then
        set the visible of graphic "rec1" to true
    else
        set the visible of graphic "rec1" to false
        end if

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by Klaus » Thu Jul 24, 2014 2:01 pm

Hi shawn,

1. it is a really bad idea to give objects a name with a "pure" NUMBER!
Beause the engine will get confused and treats -> button "1" as the button with the NUMBER 1
(lowest layer) even if that button is actually button number 666!

Use something like -> button "b1"

2. GROUPS do not have a hilite property, so what exactly do you want to achieve with:
the hilite of group "group1" ?


Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by shawnblc » Thu Jul 24, 2014 2:04 pm

Klaus wrote:Hi shawn,

1. it is a really bad idea to give objects a name with a "pure" NUMBER!
Beause the engine will get confused and treats -> button "1" as the button with the NUMBER 1
(lowest layer) even if that button is actually button number 666!

Use something like -> button "b1"

2. GROUPS do not have a hilite property, so what exactly do you want to achieve with:
the hilite of group "group1" ?


Best

Klaus
Point taken. I'll make those changes.

What I'm trying to accomplish is this (see below example):

[] Clothes
[] Pants
[] Shorts
[] Shoes
[] Socks

so if clothes is checked, then at least on of the others should be checked. If not I need a red graphic that shows around the group (pants, shorts, shoes, socks).

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by Klaus » Thu Jul 24, 2014 2:16 pm

Hi shawn,
shawnblc wrote:What I'm trying to accomplish is this (see below example):

[] Clothes
[] Pants
[] Shorts
[] Shoes
[] Socks
so this is a group of radiobuttons?
shawnblc wrote:so if clothes is checked, then at least on of the others should be checked. If not I need a red graphic that shows around the group (pants, shorts, shoes, socks).
If yes, you can check:
1. the hilitedbutton of grp "your radio group here"
Will return the NUMBER Of that button in the group
OR
2. the hilitedbuttonname of grp "your radio group here"
Will return the NAME of the button

So you could do something like this in the group script:

Code: Select all

on mouseup
  switch the hilitedbuttonname of me
  case "Clothes"
   ## do whatever needs to be done...
  break
  case "Pants"
   ## do whatever you need to to in case the user selected PANTS
  break
  ## etc...
  end switch
end mouseup
You get the picture :D


Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by shawnblc » Thu Jul 24, 2014 2:23 pm

No it's checkboxes.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by magice » Thu Jul 24, 2014 2:58 pm

how about something like this:

Code: Select all

put false into tButtonCheck
repeat with i = 1 to the number of buttons in group "group1"
if the hilite of button i of group "group1" is true then put true into tButtonCheck
end repeat

   if the hilite of btn "1" is true and tButtonCheck is false then
        set the visible of graphic "rec1" to true
    else
        set the visible of graphic "rec1" to false
        end if

not tested, but I think you'll get the idea.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: [Newbie Question] hilite of button 1 group 1 -- help ple

Post by Klaus » Thu Jul 24, 2014 3:00 pm

shawnblc wrote:No it's checkboxes.
AHA! 8)

so you need to check if one of:
[] Pants
[] Shorts
[] Shoes
[] Socks
Is checked at all or ALL are unchecked?

I ususally write little function for this:

Code: Select all

function is_something_checked
  repeat for each item tButton in "pants,shorts,shoes,socks"
    if the hilite of btn i = TRUE then
      ## At least ONE button has been checked
      return TRUE
   end if
  end repeat

  ## No button checked:
  return FALSE
end is_something_checked
Hope that helps!


Best

Klaus

Post Reply