Call a subroutine with the Tell

Hi all,
I have the following script structure:

tell application "Finder"
 -- some commands here
 -- from I want to call a subroutine:
write_text_to_file(the_Temp_path, file_data)  --- this line give me an error
end tell

on write_text_to_file(the_file, the_text)
	set file_ref to open for access the_file with write permission
	set eof file_ref to 0
	write the_text to file_ref as «class utf8»
	close access file_ref
end write_text_to_file 

The only way I found to avoid an error is to use:
tell me to write_text_to_file(the_Temp_path, file_data)

Is the best way? Or there are alternatives?
Thanks a lot

It’s the way.

Alternative syntax is

my write_text_to_file(the_Temp_path, file_data)


write_text_to_file(the_Temp_path, file_data) of me

but all forms do the same thing.

Thanks a lot!

Can’t you just move the tell application “Finder” block to the subroutine? Then the call in the main routine should work just as you had it originally (I think). What causes the error with your original script is that by being imbedded in the tell application “Finder” block the statement write_text_to_file(the_Temp_path, file_data) is being interpreted by the Finder, which doesn’t understand it. Or am I missing something? (I am a noob to AppleScripting.)

If the Finder tell block needs to be in the main routine because of the other commands (not shown), then you could just move the write_text_to_file statement down one line to pull it out of the Finder tell block, since it isn’t intended for the Finder anyway.