Hi everyone,
I have a very long AS Studio app. I found that the source of a bug was that a property, which is a list, was getting changed even though it was never set to anything!
I have a variable that I set TO the list, and then modify the variable, but never modify the actual property. Yet it changes with each modification of the variable.
I extracted the relevant code that reproduces the problem.
property C9FlavorTemplate : {"Townie", "Townie", "Townie", "Townie", "Townie", "Mafia Goon", "Mafia Goon"}
property C9Flavors : {"00 (No Cop, No Doc)", "01 (Doc, no Cop)", "10 (Cop, no Doc)", "11 (Cop and Doc)"}
tell me to generateRoles()
to generateRoles()
set randomList to my getRandomList()
set C9FlavorRoleList to my getC9FlavorList()
end generateRoles
to getRandomList()
set randomDotOrgURL to "http://random.org/sequences/?min=1&max=7&format=plain&rnd=new"
set AppleScript's text item delimiters to return
set roleResult to text items 1 thru 7 of (do shell script "curl -k -w 10 " & quoted form of randomDotOrgURL)
set AppleScript's text item delimiters to ""
return roleResult
end getRandomList
to getC9FlavorList()
set randomDotOrgURL to "http://random.org/integers/?num=1&min=1&max=4&col=1&base=10&format=plain&rnd=new"
set flavor to text item 1 of (do shell script "curl -k -w 10 " & quoted form of randomDotOrgURL) as integer
set thisFlavorList to C9FlavorTemplate
if flavor = 1 then return thisFlavorList
if flavor = 2 then set item 2 of thisFlavorList to "Doctor"
if flavor = 3 then set item 1 of thisFlavorList to "Cop"
if flavor = 4 then
set item 1 of thisFlavorList to "Cop"
set item 2 of thisFlavorList to "Doctor"
end if
return thisFlavorList
end getC9FlavorList
What happens is that making changes to the variable “thisFlavorList” changes the items in the property “C9FlavorTemplate.”
Thus the “C9FlavorTemplate” doesn’t stay as a template and screws up the second run of the script.
Is this normal behavior?
To see the bug, run the script in the debugger and see the values in the property “C9FlavorTemplate” change as changes are made to the variable thisFlavorList.