Random Chars

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
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Random Chars

Post by KennyR » Fri Feb 21, 2014 11:06 pm

Hello everyone...new question of the day for me....I am trying to assign each label of a group of buttons to a random character and am running into issues....I just simply want to randomly pick a letter between A-Z and assign the button that letter. So far I am having some luck but out of the 50 buttons I have in the group, only about 1/2 of those actually get a random character. Not sure why...I am using a repeat loop to assign each button a random letter from a field...maybe someone can help....thanks

Code: Select all

local pLetter
on mouseUp
   repeat with x=1 to the number of btns in group "alpha"
       put any char of fld "alphabet" into pLetter
      set the label of btn x to pLetter
      put empty into pLetter
      end repeat
end mouseUp 

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

Re: Random Chars

Post by Dixie » Fri Feb 21, 2014 11:29 pm

50 buttons and 26 letters in the alphabet... or am I missing something ?

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Random Chars

Post by KennyR » Fri Feb 21, 2014 11:30 pm

LOL! I did think of that....I repeated the alphabet in the field like 75 times!! Nice one though!

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Random Chars

Post by LCNeil » Fri Feb 21, 2014 11:44 pm

Hi Kenny,

Try specifically referencing the "alpha" group when setting the button names
set the label of btn x of group "alpha" to pLetter
I created a quick test stack that change all buttons as expected
randombuttonalpha.livecode.zip
(2.07 KiB) Downloaded 257 times
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Random Chars

Post by KennyR » Fri Feb 21, 2014 11:53 pm

Roger, Thank you very much for taking the time to construct that example for me! That was awesome! Works EXACTLY as I wanted....

Best
Kenny

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Random Chars

Post by LCNeil » Fri Feb 21, 2014 11:55 pm

Glad I was able to help :) Have a great weekend.

 Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

Post Reply