Newb question about functions

Hi there, sorry if this is a dumb question, but I’ve been searching for 2 days on how to sort this problem.

I’m using an explode function I found on another forum which work great in Script Editor, but when trying to use it in ASS I get an error

Where should I be putting custom functions so that they are usable?
Please let me know if you want to see my code, and thanks in advance for any help.

Hi piers,

there is no explode keyword in plain AppleScript.
You probably use a Scripting Addition or you talk to an application, whose dictionary contains this keyword

Thanks for the quick reply Stefan, at the top of my script I have,

on explode(separator, input)
	local separator, input
	if separator is "" then return false
	
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {separator}
		set input to text items of input
	end try
	set AppleScript's text item delimiters to ASTID
	return input --> list
end explode

which is followed by


on clicked theObject
	
	tell window of theObject
		
		if the name of theObject is equal to "connectbutton" then
set emailaddress to contents of text field "usernamefield" as text
set myusername to item 1 of explode("@", emailaddress) as text
...

but as soon as I click the button I get the error?

within a tell block you must add my,
because the window has no idea what a handler is.
my passes the request to AppleScript itself, which can execute the handler

.set myusername to item 1 of my explode("@", emailaddress)
.

Note: the as text coercions are probably not needed, a text field contains text

:smiley: Thank You! that works perfectly now :smiley:

Gosh, its easy when you know how, I really need to buy an applescript studio book, any recommendations?

I’d prefer a book about plain AppleScript to learn the basics like
Hanaan Rosenthal: The Comprehensive Guide
or
Matt Neuburg: AppleScript: The Definitive Guide

AppleScript Studio is very well documented and there are lots of sample projects included