I'm trying to create an array of images from a file and then call a random image from the array and have it display in an image area. To do this I have a button with the following code
Code: Select all
global distractorArray
global distractorNumber
on mouseUp
local tFolder
answer folder ""
put it into tFolder
-- asks the user to pick a folder (with images) and then put it into a variable for manipulation
doForEachFile tFolder
-- now we pull out the images using this function
if there is a folder tFolder then
put tFolder into field "Field"
end if
-- puts the folder path into a field to make sure the program actually recieved a folder
end mouseUp
on doForEachFile tFolder
set defaultFolder to tFolder
-- set defaultFolder to tFolder so we can begin pulling files from the folder
put 1 into distractorNumber
-- this will be used to assign the files a location within the array
-- Also will be used later to help pick a random from 1 to however many files
repeat for each line tFile in tFolder
-- goes through every file in the folder and performs the tasks within the repeat loop
createArray (tFile)
-- where the array is acutally made
add 1 to distractorNumber
-- distractorNumber increases by 1 everytime this is repeated to for location assignment within the array
end repeat
end doForEachFile
on createArray tFile
if there is a file tFile then
-- checks that there is a file
put tFile into distractorArray[distractorNumber]
--put individual images into the array, at location distractorNumber (should increase by one everytime the script is run)
end if
end createArray
the image field in on the next card and the code for it is as follows:
Code: Select all
global distractorArray
global distractorNumber
global distractorDisplay
on openCard
getRandom
set the filename of img "Image" to distractorArray[distractorDisplay}
end openCard
on getRandom
put random(distractorNumber) into distractorDisplay
end getRandom
Also, the comments are for the code above them.
Thanks for your help,
Jeff