does applescript do subroutines?

I have a script that has 3 parts to it. Lets call them x,y,z. They are done in the order of x,y,z. I also have 3 conditions that exist. Each one correlates to x,y,z . I want to run each script of x,y,z only if there cooresponding condition is true. Here is an example.

script checks, and finds

condition 1 is true (for x)
condition 2 is false (for y)
condition 3 is true (for z)

so this is what should happen

script x
skip script y (because it did not meet its condition)
script z

Can someone tell me how this is done? I know of other subroutines, but not applescripts.

You actually want x, y, and z to be separate scripts? Why not just three different handlers?

set X to true
set y to false
set z to true

if X then do_x()
if y then do_y()
if z then do_z()

to do_x()
	display dialog "X"
end do_x

to do_y()
	display dialog "Y"
end do_y

to do_z()
	display dialog "Z"
end do_z

Hi,

Here’s an example:

script Script1
display dialog “I’m script 1.”
end script

script Script2
display dialog “I’m script 2.”
end script

script Script3
display dialog “I’m script 3.”
end script

set script_list to {Script1, Script2, Script3}
set the_conds to {true, false, true}
set script_count to count script_list
repeat with i from 1 to script_count
set this_cond to (item i of the_conds)
if this_cond then
run script (item i of script_list)
end if
end repeat

gl,

Thanks! Working great!

I was thinking that you could eliminate the list of boolean by adding a script property:

script Script1
property enabled : true
display dialog “I’m script 1.”
end script

script Script2
property enabled : false
display dialog “I’m script 2.”
end script

script Script3
property enabled : true
display dialog “I’m script 3.”
end script

set script_list to {Script1, Script2, Script3}
set script_count to count script_list
repeat with this_script in script_list
set this_cond to enabled of this_script
if this_cond then
run script this_script
end if
end repeat

gl,