kelyanok wrote: ↑
Tue Apr 14, 2020 12:58 pm
Code: Select all
put "1,2,3,4,5,6,7,8,9" into theList
sort items of theList by random(10000)
repeat with N = 1 to 9
put item N of theList into fld ("playerRole" & N)
put "theres no such object". ive put playerRole" space and all numbers from 1 to 9.
Is the problem that it's not getting to the field?
Is your field labelled: playerRole 1, playerRole 2, etc? (i.e. has space)
Or, is it playerRole1, playerRole2, etc.? (i.e. has no space)
("playerRole" & N) will come out as playerRoleN (where N is your number) - note no space
("playerRole" & space & N) will come out as playerRole N (where N is your number)- note the space.
Also, if you're worried about players getting multiple roles (i.e.Player 1 and 2 getting role 5), you may be able to run a loop that checks the latest selection against a list of previous selections. TBH, I am not sure about the sort command by random 10000. The dictionary doesn't have a great explanation of it. If I were doing it, I would have 1-9 in a list, select a random number from 1 to 9, assign that number to player 1, then delete that item of the list. Repeat with random (8) to player 2, delete that item number,repeat with random (7) to player 3,etc. until you have one player left and 1 item in the list. It's the same theory that you would use if you were dealing a deck of cards in random order- select it at random, take it out of the potential choices.
Hope that helps.