Annoying subs

on subinsert_(sender)
		
		tell application "AppleScript Editor"
			activate
			set valscptsel to (contents of selection)
			if valscptsel is not "" then
				tell application "Dialog Maker" to activate
				winwarning's makeKeyAndOrderFront_(sender)
			else
				subgo("no")
				
			end if
		end tell

followed by

	on subgo(valcopy)
		try
			winwarning's performClose_(sender)
		end try
		set valtext to (valwintext's |string|() as string)
		
		if (valwinent's intValue()) is 0 then
			set valent to " default answer \""
			set valentdef to (valwinentdef's stringValue() as string)
			if (valwinentsec's intValue()) is 0 then
				set valentsec to "\" with hidden answer"
			else
				set valentsec to "\""
			end if
		else
			set valent to ""
			set valentdef to ""
			set valentsec to ""
		end if
		
		if (valwinbut's intValue()) is 0 then
			set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\"}"
			if (valwinbut2chk's intValue()) is 1 then
				set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\",\"" & (valwinbut2's stringValue()) & "\"}"
				if (valwinbut3chk's intValue()) is 1 then
					set valbut to " buttons {\"" & (valwinbut1's stringValue()) & "\",\"" & (valwinbut2's stringValue()) & "\",\"" & (valwinbut3's stringValue()) & "\"}"
				end if
			end if
		else
			set valbut to ""
		end if
		
		if (valwinbutdef's indexOfSelectedItem()) is 0 then
			set valbutdef to ""
		else
			set valbutdef to " default button " & (valwinbutdef's indexOfSelectedItem())
		end if
		
		if (valwinbutcal's indexOfSelectedItem()) is 0 then
			set valbutcal to ""
		else
			if (valwinbutcal's titleOfSelectedItem() as string) is "OK" then
				set valbutcal to " cancel button 2"
			else
				set valbutcal to " cancel button " & (valwinbutcal's indexOfSelectedItem())
			end if
		end if
		
		if (valwintit's intValue()) is 0 then
			if (valwintitchs's intValue()) is 0 then
				set valtit to " with title \"" & (valwintitnam's stringValue()) & "\""
			else
				set valscptnam to (get the name of the front window of application "AppleScript Editor")
				set valtit to " with title \"" & valscptnam & "\""
				
			end if
		else
			set valtit to ""
		end if
		
		tell application "AppleScript Editor"
			activate
			set valdialog to "display dialog \"" & valtext & "\"" & valent & valentdef & valentsec & valbut & valbutdef & valbutcal & valtit --& valicon & valtmout
			(*if valcopy is "yes" then
				set the clipboard to valdialog
			else*)
			tell application "System Events"
				keystroke valdialog
			end tell
			--end if
		end tell
		tell application "Dialog Maker" to activate
	end subgo

doesn’t work even with the valcopy if statement commented out but if you put the exact same contents of subgo inside the subinsert rather than calling subgo it works

the error is

OMG please somebody explain why putting ‘my’ in front makes it work, nobody ever explains this! Strange how I worked it out a minute after posting XD.

Hi,

a common error. No application knows what a handler is, only AppleScript itself does

my subgo("no")

Also a separate IBaction sub calls it fine without ‘my’???

	on subcopy_(sender)
		subgo("yes")
	end subcopy_

The problem is the scope of the application tell block.
It’s always (strongly) recommended to use application tell blocks only for lines which contain appropriate application terminology

You mean current application tells?
What appropriate application terminology?

It works perfectly now. Except for the problem in my other post.

I mean this


tell application "AppleScript Editor"
	activate
	set valscptsel to (contents of selection)
end tell
if valscptsel is not "" then
	tell application "Dialog Maker" to activate
	winwarning's makeKeyAndOrderFront_(sender)
else
	subgo("no")
end if

tell AppleScript Editor is used only for the activate and selection lines.
This avoids nested application tell blocks (Dialog Maker) and the problem with the handler call

A command is a command is a command. Application-defined commands like to use a different syntax to user-defined commands, but the actual mechanics are are the same. All commands within a tell block are sent to whatever object is specified by that tell block by default. Adding ‘my’ before the command name (which is the same as writing ‘command_name() of me’) informs AppleScript that you want the command sent to the current script instead.

Ahhh yes, I realised that now (as in I realised just before your last comment Stefan XD), but I only realised the end tell was unnecessarily low by you telling me, I think it used to contain what is now the contents of subgo before I changed the structure to incorporate the warning window, causing this. Thanks :slight_smile:

If you don’t mind I would be grateful if you took a look at my weird behaviour post, because some how I don’t think it’s my fault. :confused: :lol: