Newbie, please help

Hi All,

I just read thru the document and starting write some script; however I got problem with calling function. Below is my script.

on inputText intxt
if my intxt is not empty then
repeat with each item of intxt
put it
end repeat
else
put ("list is empty")
end if
end inputText

put inputText("a,b,c")

When I run script, nothing happen. The result should be like
a
b
c

I'm very appreciated all of your inputs.

Best Regards

Comments

  • JonathanOSXJonathanOSX ForumAdmin admin
    There are a few issues here. So let's break them down one by one.

    The first is that when you run the code sample as it appears above, Eggplant treats everything up until the ON declaration as the "initial handler" of the script and executes that - in this case it's just some blank lines, so nothing gets executed. To solve this you could break your inputText handler out into it's own script or else simply move your call to it up to the front of the script.

    Next up is that the call to:
    put InputText("a,b,c")
    
    Since inputText is declared as an ON handler and not a Function Handler it can't be used in this way. So either we need to switch inputText to be a function or else we just call it on a line by itself without the put:
    InputText("a,b,c")
    
    Finally, in inputText itself you don't want to do "my intxt" which is trying to access a property called intxt. Instead just refer to the local variable directly, without the "my".

    So here is a corrected script which does what you are looking for
    inputText("a,b,c")
    
    on inputText intxt 
    	if intxt is not empty then 
    		repeat with each item of intxt 
    			put it 
    		end repeat 
    	else 
    		put "list is empty"
    	end if 
    end inputText 
    
    Hopefully this little example helps clear up some things. If you need any other help please don't hesitate to post or send a support request.
  • Thanks, Jonathans

    Your explaination is very clear.

    Best Regards
Sign In or Register to comment.