Page 1 of 1

Helping beginners

Posted: Sat Aug 25, 2012 10:46 am
by jon
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

Re: Helping beginners

Posted: Sat Aug 25, 2012 10:52 am
by Mark
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

Re: Helping beginners

Posted: Sat Aug 25, 2012 10:58 am
by Dixie
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

Re: Helping beginners

Posted: Sat Aug 25, 2012 11:03 am
by jon
As quick as that, how's that for service :)

you got it one, thanks for that Mark and Dixie :)

Re: Helping beginners

Posted: Sat Aug 25, 2012 11:07 am
by Klaus
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

Re: Helping beginners

Posted: Sat Aug 25, 2012 11:17 am
by jon
Klaus

You just can't resist a challenge :)

from more than 20 lines to four, from all of you, thank you.

Re: Helping beginners

Posted: Sat Aug 25, 2012 11:46 am
by Klaus
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