When calling a script with parameters, I’m seeing some inconsistent behaviour.
Consider this script fragment …
set path to my folder's folder & "Data/OzOrgNames.txt"
Set counter = 33
Set loops = 0
Repeat with OrgDetails = each line of file path
if loops < 4 then
Set OrgName = (Item 1 of OrgDetails) & counter
Set OrgCode = (Item 2 of OrgDetails) & counter
AddNewStateFromText OrgName, counter
// AddNewStateFromText( OrgName, counter)
end if
set loops = loops + 1
end repeat
which calls this script … and I only need the first couple of lines from this to explain the problem …
params OrgName, nCounter
put the params
log "nCounter in NewState : " & nCounter
log "OrgName in NewState : " & OrgName
The pertinent lines in the first script are the call to AddNewStateFromText, towards the end of that script. As you can see, I have two versions of that call, one being to call it as a command, the other as a function.
Here’s the relevant log entries when calling it as a command …
addnewstatefromtext "Ray White Real Estate33","33"
Thu, 12/06/08 10:09:49 AM log nCounter in NewState : 33
Thu, 12/06/08 10:09:49 AM log OrgName in NewState : Ray White Real Estate34
And here’s the equivalent log entries when calling it as a function …
addnewstatefromtext ("Ray White Real Estate33", "33")
Thu, 12/06/08 10:08:23 AM log nCounter in NewState :
Thu, 12/06/08 10:08:23 AM log OrgName in NewState : (Ray White Real Estate33,33)
The problem arises with the values assigned to nCounter and OrgName in the called function: When called as a command, the data assignments are correct, and are able to be used by the function, but if the routine is called as a function, the value intended for nCounter is appended to the value assigned to OrgName, and nCounter is left as null.
This, of course, causes serious issues further downstream, as any subsequent dependencies are now rendered incorrectly.
As I need to use the functional version of the call, could somebody please tell me what is happening here?