Page 1 of 1

Randomly generating buttons and assigning them a name

Posted: Mon Feb 27, 2012 12:01 am
by d.m.holdawayGA2553
Hello,

i was wondering if anyone could help me?

i have searched the forum for an answer but could not find one, i also tried google.

Using code i am trying to generate random buttons and then assigning the buttons either A,B or C

so far i have

Code: Select all


on createrandombutton

   put random(3) into tLetter
   if tLetter = 1 then put A into pLetter
   else 
      if tLetter = 2 then put B into pLetter
      else 
         if tLetter = 3 then put C into pLetter
      end if 
   end if 

create button ("button&pLetter) in group "buttongroup"

end createrandombutton 

am i going in the right direction, or is this just wrong?

so if anyone could shed some light on this issue or put me in the right direction that would be amazing

thanks for taking the time to view this post.

Re: Randomly generating buttons and assigning them a name

Posted: Mon Feb 27, 2012 12:11 am
by sturgis
Don't know if its a typo or not but you will get an error on the create line because you don't have matching quotes around your string.

change this:
create button ("button&pLetter) in group "buttongroup"

to this:

create button ("button" & pLetter) in group "buttongroup"

In addition, there is an easier way to do the randomizing.

put any item of "A,B,C" into pLetter -- will grab a random letter from the string

So your handler can be simplified into

Code: Select all

on createrandombutton
   put any item of "A,B,C" into pLetter
   create button ("button" & pLetter) in group "buttongroup"
end createrandombutton 

Re: Randomly generating buttons and assigning them a name

Posted: Mon Feb 27, 2012 12:55 am
by d.m.holdawayGA2553
yes it was a typo,

thanks you for the advice and code sample.