Hiding more than one object in one command?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Hiding more than one object in one command?

Post by peter.s » Sun Oct 03, 2010 4:43 am

Hi there,

I apologise if this is one of those "couldn't see it for its simplicity" questions, but I just can't figure it out...

How can I hide multiple objects (multiple fields and/or multiple buttons) in the fewest lines of code?

For example: I can hide a button with

Code: Select all

on mouseUp
     hide button "ButtonOne"
end mouseUp
But how to do it for multiples without having a long list of code like, for example...

Code: Select all

on mouseUp
     hide button "ButtonOne"
   hide button "ButtonTwo"
   hide button "ButtonThree"
-- etc.
end mouseUp
Cheers,

Peter

RogerK
Posts: 4
Joined: Thu Jul 29, 2010 10:20 am

Re: Hiding more than one object in one command?

Post by RogerK » Sun Oct 03, 2010 5:33 am

Peter,

You could try including all the objects you want to hide in a single group, then hide or show the group.

Would that work for your particular needs?

RogerK

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Hiding more than one object in one command?

Post by peter.s » Sun Oct 03, 2010 6:27 am

Hi Roger,

Thanks for your reply - unfortunately grouping the objects won't help here.

I need different elements (objects/buttons) to be shown or hidden depending on which buttons are activated. I would imagine writing scripts to group and ungroup different collections of objects in order to hide or show them, would be much the same as simply listing each of them for each button.

I tried using square brackets, eg: ["ButtonOne" "ButtonTwo" "ButtonThree"], but that doesn't work either...

Peter

nsrev
Posts: 6
Joined: Thu Apr 09, 2009 10:46 am

Re: Hiding more than one object in one command?

Post by nsrev » Sun Oct 03, 2010 9:32 am

Name the buttons as Button1, Button2, Button3 then use a loop such the following:
on mouseUp
repeat with i = 1 to 3
hide button ("button" & i)
end repeat
end mouseUp

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Hiding more than one object in one command?

Post by peter.s » Sun Oct 03, 2010 10:28 am

Thanks!

I can see the logic with this - very neat, but I would have to add something to exclude particular buttons I don't want hidden.

Out of interest... Is it recommended to use a loop like described above and not recommended to have a list (like I've described in my initial post above), which includes say 20 buttons? Or does it make little difference which way it's done?

Cheers,

Peter

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Hiding more than one object in one command?

Post by Klaus » Sun Oct 03, 2010 11:02 am

Hi Peter,

I'm afraid you will not be ab le to avoid writing a list of all button names you want to hide, if nsrev's script does not fit for you.

But you could try this:

Code: Select all

...
put "Button2,Button 666,Button 788,Another Button,an another one" into tList
repeat for each item i in tList
   hide btn i
end repeat
...
Best

Klaus

RogerK
Posts: 4
Joined: Thu Jul 29, 2010 10:20 am

Re: Hiding more than one object in one command?

Post by RogerK » Sun Oct 03, 2010 11:19 am

Peter,

If you have to live with the loop solution, remember to "lock screen" at the start of your script. It'll run much faster and will avoid any strange screen effects as items disappear.

Cheers

RogerK

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Re: Hiding more than one object in one command?

Post by Regulae » Sun Oct 03, 2010 12:52 pm

Hi Peter,

I've made a small sample stack to illustrate one approach to the problem. There's a discussion field which explains how it works.

Regards,
Michael
Attachments
ShowHideControls.zip
(2.16 KiB) Downloaded 264 times

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Hiding more than one object in one command?

Post by peter.s » Mon Oct 04, 2010 4:14 am

I must say - this forum is invaluable for beginners/dabblers like me.

A big Thank You! to everyone who contributed to this post! Each contribution has been helpful and Michael's sample stack is a neat bonus. I feel I have a lot to move forward with now...

Kind regards,

Peter

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Hiding more than one object in one command?

Post by Mark » Tue Oct 05, 2010 9:03 am

Peter,

You might want to lock the screen at the start of your script and unlock it at the end (search for lockScreen in the dictionary).

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”