Helping beginners

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
jon
Posts: 52
Joined: Sat Apr 14, 2007 11:44 am

Helping beginners

Post by jon » Sat Aug 25, 2012 10:46 am

Hi
As a hobbyist/beginner I know when I'm looking around for answers to help me do better, I always learn lots from the experts on here.

I thought it would help me and others looking for answers to fairly basic coding techniques if we posted snippets of code
and asked the experts to show us ways of making the snippet better, shorter, faster so that we can learn more and code faster.
Here is one snippet that works but maybe could be more efficient, ( or is this the best way to do it? ) I don't know, any advice please?
Kind regards, Jon

Code: Select all

command mveDice
   //Move all dice back to sleep position
   doHideDiceScores
   doHideScores
   set the disabled of group "visButs" to true
   set the visible of image "dice1.jpg" to false
   set the Loc of image "dice1.jpg" to 402, - 20
   set the visible of image "dice2.jpg" to false
   set the Loc of image "dice2.jpg" to 402, - 20
   set the visible of image "dice3.jpg" to false
   set the Loc of image "dice3.jpg" to 402,- 20
   set the visible of image "dice4.jpg" to false
   set the Loc of image "dice4.jpg" to 402, - 20
   set the visible of image "dice5.jpg" to false
   set the Loc of image "dice5.jpg" to 402, - 20
   set the visible of image "dice6.jpg" to false
   set the Loc of image "dice6.jpg" to 402, - 20
   set the visible of image "dice11.jpg" to false
   set the Loc of image "dice11.jpg" to 402, - 20
   set the visible of image "dice21.jpg" to false
   set the Loc of image "dice21.jpg" to 402, - 20
   set the visible of image "dice31.jpg" to false
   set the Loc of image "dice31.jpg" to 402, - 20
   set the visible of image "dice41.jpg" to false
   set the Loc of image "dice41.jpg" to 402, - 20
   set the visible of image "dice51.jpg" to false
   set the Loc of image "dice51.jpg" to 402,- 20
   set the visible of image "dice61.jpg" to false
   set the Loc of image "dice61.jpg" to 402, - 20
end mveDice
I dare not shake the dew drop from a rose lest I disturb the stars.

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

Re: Helping beginners

Post by Mark » Sat Aug 25, 2012 10:52 am

Hi Jon,

It depends on what exactly you try to achieve and why. It also depends on what other objects are on your card or in your stack, but the following script basically does the same as yours:

Code: Select all

on mveDice
  doHideDiceScores
  doHideScores
  disable grp "visButs"
  repeat with x = 1 to number of images
    if the short name of img x contains "dice" then
      set the loc of img x to 402,-20
      hide img x
    end if
  end repeat
end mveDice
Kind regards,

Mark
Last edited by Mark on Sat Aug 25, 2012 11:32 am, edited 1 time in total.
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

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Helping beginners

Post by Dixie » Sat Aug 25, 2012 10:58 am

Hi...

This might save you some lines...

Code: Select all

command mveDice
   put "1,2,3,4,5,6,11,21,31,41,51,61" into diceNumber
   
   //Move all dice back to sleep position
   doHideDiceScores
   doHideScores
   set the disabled of group "visButs" to true
   
   repeat with count = 1 to the number of items of diceNumber
      set the visible of image "dice" & item count of diceNumber & ".jpg" to false
      set the loc of image "dice" & item count of diceNumber & ".jpg" to 402,-20
   end repeat
end mveDice
be well,

Dixie

jon
Posts: 52
Joined: Sat Apr 14, 2007 11:44 am

Re: Helping beginners

Post by jon » Sat Aug 25, 2012 11:03 am

As quick as that, how's that for service :)

you got it one, thanks for that Mark and Dixie :)
I dare not shake the dew drop from a rose lest I disturb the stars.

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

Re: Helping beginners

Post by Klaus » Sat Aug 25, 2012 11:07 am

Hi friends,

using parens where indicated does not hurt, au contraire mes amies :D

Code: Select all

...
repeat with count = 1 to the number of items of diceNumber
   set the visible of image ("dice" & item count of diceNumber & ".jpg") to false
   set the loc of image ("dice" & item count of diceNumber & ".jpg") to 402,-20
end repeat
...
Best

Klaus

jon
Posts: 52
Joined: Sat Apr 14, 2007 11:44 am

Re: Helping beginners

Post by jon » Sat Aug 25, 2012 11:17 am

Klaus

You just can't resist a challenge :)

from more than 20 lines to four, from all of you, thank you.
I dare not shake the dew drop from a rose lest I disturb the stars.

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

Re: Helping beginners

Post by Klaus » Sat Aug 25, 2012 11:46 am

Hi Jon,
jon wrote:Klaus

You just can't resist a challenge :)
No comment :D

But the thing with the parenthesis is not a challenge but neccessary, believe me!


Best

Klaus

Post Reply