Looping script objects

Hi

Very new to script objects, hence the question. What I am trying to do is loop 2 script objects - something like this


tell y to run
repeat
	script x
		display dialog "x"
	end script
	
	script y
		display dialog "y"
		tell x to run
	end script
end repeat


This fails. Telling script y to run outside or inside the repeat loop does not work. Would be most grateful for any solutions and perhaps an explanation of why this does not work.


script x -- child script of me script
	display dialog "x"
end script

script y -- child script of me script
	display dialog "y"
	tell x to run
end script

repeat
	tell y to run
end repeat

or:


script y -- parent script of x script, and child script of me script
	script x -- child script of y script
		display dialog "x"
	end script
	display dialog "y"
	run x
end script

repeat
	tell y to run
end repeat

or this (equivalent of 2nd scheme):


script y
	display dialog "y"
	run script "display dialog \"x\""
end script

repeat
	run y
end repeat

Thank you KniazidisR

I was trying when you re[plied to combine both scripts and it was proving to nightmare.
That saved me hours :slight_smile:

After playing for a while I also found I could do this. Apologies if this is script object 101 but at least I was excited!

script y 
	script x 
		display dialog "x"
		tell y to run
	end script
	
	display dialog "y"
	run x
end script


script a
	
	script c
		display dialog "c"
		tell y to run
	end script
	
	script b 
		display dialog "b"
		tell c to run
	end script
	
	display dialog "a"
	tell b to run
end script

tell a to run