Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ShuddaRunThat

macrumors newbie
Original poster
Apr 1, 2014
5
0
Hi - I have a large script that within which I have a number of handlers. I also have a large set of records. I cannot get the handlers to use the contents of the records so my current workaround is to remove the handlers and drop their code into the relevant points in the script to make this script effectively one large RUN handler. I understand a bit about set, global and property - but not sure how to apply this scope setting to a record list. is there a way to make a set of records scope global across all handlers in the script?

thanks
 
Perhaps not the answer you are looking for but here's an example from the ASLR_about_handlers

A parameter pattern can be much more complex than a single list. The handler in the next example takes two numbers and a record whose properties include a list of bounds. The handler displays a dialog box summarizing some of the passed information.

Code:
on hello(a, b, {length:l, bounds:{x, y, w, h}, name:n})
    set q to a + b
 
    set response to "Hello " & n & ", you  are " & l & ¬
        " inches tall and occupy position (" & x &  ", " & y & ")."
 
    display dialog response
 
end hello
 
set thing to {bounds:{1, 2, 4, 5}, name:"George", length:72}
hello (2, 3, thing)
--result: A dialog displaying "Hello George, you are 72 inches  tall
--          and occupy position (1,2)."

The properties of a record passed to a handler with patterned parameters don’t have to be given in the same order in which they are given in the handler’s definition, as long as all the properties required to fit the pattern are present.
 
A property or global variable would allow the record to be used, well, globally. In order for anyone to help diagnose the problem, you will need to provide more specific information about the conditions where you are not able to access the record.
 
more specific example

this shows an example of the problem...

Code:
set people to {{name:"Fred", Mood:"Happy"}, {name:"Jim", Mood:"Sad"}, {name:"Gary", Mood:"Happy"}}

on changeMood()
	
	set whoseHappy to {}
	
	repeat with theRecord in people
		if Mood of theRecord = "Happy" then
			set end of whoseHappy to name of theRecord
		end if
	end repeat
	
	set pickMoodChange to (choose from list whoseHappy default items "" with prompt "who is not happy?") as string
	
end changeMood

changeMood()

run it and you will see the problem. basically code inside the handler does not know that the records exists - if I take the code out of the handler and run it, it works fine.
 
Last edited by a moderator:
Your record is not set as a global - in this case it is essentially a local variable of the (implied) run handler. You will need to use something like:

Code:
global people
set people to {{name:"Fred", Mood:"Happy"}, {name:"Jim", Mood:"Sad"}, {name:"Gary", Mood:"Happy"}}

     -- or --

property people : {{name:"Fred", Mood:"Happy"}, {name:"Jim", Mood:"Sad"}, {name:"Gary", Mood:"Happy"}}
 
Couldn't you pass "people" as a parameter to changeMood(), which I believe was the point of a previous poster.
 
many thanks red menace i figured it was to do with the records not being set globally but was missing the : out of the property command - many thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.