property of library loaded in script Server, impossible to set and get

Hello.

I’m really trying hard to be able to set and get a property in a script object which are loaded into a script server. The following code is just for illustrating.

The code below breaches everything which I intended to do, as i uses the my keyword, and it’s own name, which would be the same as it got in the server. And even this doesn’t work even it is a totally fake.


script _1_objLib
	property txtColor : missing value
	
	on isFavcolor()
		
		log "FAVCOLOR LIB isFavcolor  : my new color is : " & (txtColor of my _1_objLib)
		if (txtColor of my _1_objLib) is missing value or (txtColor of my _1_objLib) is "" then
			return false
		else
			return true
		end if
	end isFavcolor
	
	on setFavColor(theColor)
		
		set (txtColor of my _1_objLib) to theColor
		log "FAVCOLOR LIB setFavColor() : my new color is : " & (txtColor of my _1_objLib)
		
	end setFavColor
	
	on getFavColor()
		log "FAVCOLOR LIB getFavColor() : my new color is : " & (txtColor of my _1_objLib)
		return (txtColor of my _1_objLib)
	end getFavColor
end script

This is an example of a Small server.


property _1_objLib : missing value
property toplevel : (me)
on run
	set my toplevel's _1_objLib to _1_objLib of (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:favColorLib2.scpt")

on objLib()
	return my toplevel's _1_objLib
end run

The client script which calls the Server.m (I assume that the my keyword ends within the application, that is something I will experiment with as soon as this post is written.


tell application "ScriptLibraryServer"
	
	if its objLib()'s isFavcolor() is true then
		set myColor to its objLib()'s getFavColor()
		tell me
			activate
			display dialog "FavColor " & myColor
		end tell
		
	else
		tell me
			activate
			display dialog "No color defined yet"
		end tell
	end if
	
	its objLib()'s setFavColor("Blue")
	set its objLib()'s txtColor to "Blue"
	--	set objLib()'s txtColor to "ORANGE"
	log its objLib()'s txtColor ”>(* missing value *)
	
	if its objLib()'s isFavcolor() then
		set myColor to its objLib()'s getFavColor()
		display dialog "FavColor " & myColor
	else
		tell me
			activate
			display dialog "No color defined yet"
		end tell
	end if
	log its (objLib()'s txtColor) ”> (* missing value *)
end tell

I still may have some experiments for giving it totally up, but if some of you know how to do this: (The objective is to be able to set and get a property in a script object in a library loaded into a script server.) Please don’t hesitate.
Also if you are totally sure of that it can’t be done this way at all, but that I have to go through a proper tylist or something. I just want to tell you that the reason for this is encapsulation, I know that I can pass in a parameter from the outside and store that in the client script, that is not the issue. The issue is really to have a separate piece of functionality within a script server, which handles its own data, at least as long as it is running.

Hello. I found a way to make it work by reading Bill Cheeseman’ss article about script servers.

New version of the client script, I tell the handler which returns the script object in order to do things with it, and that works. It is now left to rearrange the original library script into something proper, what is there defies everything about encapsulation since it uses the keyword my, and in reality addresses its properties via the the script server.
I’ll post all of the “working” demo code here when I have a real working soloution.

Hello.

Revised client script that succeed in setting and getting a property from a script server.


tell application "ScriptLibraryServer"
	
	tell its objLib()
		-- Notice: we address the specific script object in the Script server by "telling it"
		-- in order for the code to work
		if its isFavcolor() is true then
			set myColor to its getFavColor()
			tell me
				activate
				display dialog "FavColor " & myColor
			end tell
			
		else
			tell me
				activate
				display dialog "No color defined yet"
			end tell
		end if
		
		its setFavColor("Blue")
		set its txtColor to "Blue"
		--	set objLib()'s txtColor to "ORANGE"
		log its txtColor
		
		if its isFavcolor() then
			set myColor to its getFavColor()
			display dialog "FavColor " & myColor
		else
			tell me
				activate
				display dialog "No color defined yet"
			end tell
		end if
		log its txtColor
	end tell
end tell

A library script that works like that it is intended to.


script objLib
	property txtColor : missing value
	
	on isFavcolor()
		
		log "FAVCOLOR LIB isFavcolor  : my new color is : " & (txtColor of my objLib)
		if txtColor of objLib is missing value or txtColor of objLib is "" then
			return false
		else
			return true
		end if
	end isFavcolor
	
	on setFavColor(theColor)
		
		set txtColor of objLib to theColor
		log "FAVCOLOR LIB setFavColor() : my new color is : " & (txtColor of objLib)
		
	end setFavColor
	
	on getFavColor()
		log "FAVCOLOR LIB getFavColor() : my new color is : " & (txtColor of objLib)
		return (txtColor of objLib)
	end getFavColor
end script

A very simple ScriptLibraryServer which gives access to the script library in question


property _1_objLib : missing value
property toplevel : (me)
on run
	set my toplevel's _1_objLib to objLib of (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:favColorLib2.scpt")
end run
on objLib()
	return my toplevel's _1_objLib
end objLib