using repeat loops to add info

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

using repeat loops to add info

Post by PoLyGLoT » Sat Sep 29, 2012 8:34 pm

Hi,

I've randomized the numbers 1-12. I'm trying to use the random numbers one at a time to put information into a different bin (i.e., if the first number is 6, I want to put the information in card field "6" into bin1; if the second number is 4, I want to put the information in card field "4" into bin2, etc.). I need to do this for all 12 numbers.

This code doesn't work:

sort lines of card field "randombin" of card "orders" by random(12) #sorts my numbers
repeat with x = 1 to 12
put item 1 of line x of card field "randombin" of card "orders" into y
put card field y of card "main task materials" into matlist(x) <-------------------How can I use the "x" in the repeat loop to add 1(so that it starts with matlist1, then matlist2, etc....)
end repeat

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

Re: using repeat loops to add info

Post by Mark » Sun Sep 30, 2012 10:08 am

Hi,

Here's an example:

Code: Select all

local lMatList

constant k12 = "1,2,3,4,5,6,7,8,9,10,11,12"

on makeArray
  put k12 into myVar12
  sort items of myVar12 by random(number of items of k12)
  repeat with x = 1 to number of items of k12
   // use square brackets to make new array
    put card fld (item x of myVar12) of cd "main task materials" into lMatList[x]
  end repeat
end makeArray
Kind regards,

Mark
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

Post Reply