string values returned from the text

Hi
In my ASOBC script I have some code like the below, the property’s are bound to
text fields in IB and when a button is clicked the string values are retrieved and then
the next piece of code opens a scpt file from the main bundle, this works fine.

What I cant figure out is how to get the string values returned from the text
fields to the scpt file as variables, could some one please show me how?

script BMMAAppDelegate
	property parent : class "NSObject"
	---------------------------------------------------------------------
	---  PROPERTYS
	---------------------------------------------------------------------
	property A : missing value
	property B : missing value
	
on CreateWin_(sender)

set ENT to A's stringValue()
set ENT to ENT as string
-----
set ENW to B's stringValue()
set ENW to ENW as string

set posixPath to current application's NSBundle's mainBundle's pathForResource_ofType_("BMMANUAL", "scpt") as string 
					set scriptAlias to (posixPath as text) as POSIX file
					run script scriptAlias
end CreateWin_

I’ll help, only if you give me the project. I’m a little confused about the scpt file.

If you load the script into a variable first, then use run, you can just use the same variable name – inheritance will take care of things for you.

hi

thanks for the reply’s guys, but im still not getting it, using the below called from the code above, or have i completely misunderstood?.


the rest of the scpt file runs fine apart from getting the variables across from the main script
to it, the variables are used in the scpt file like this

on BTFF()

--tried this & failed 
set _WHeight to ENT's stringValue()
set _WWidth to ENW's stringValue() 
set WSize3 to {_WHeight, _WWidth}

--tried this & failed
set _WHeight to ENT as string
set _WWidth to ENW as string
set WSize3 to {_WHeight, _WWidth}

--tried this & failed
set WSize3 to {ENT, ENW}	

end BTFF

If you want variables to be seen by the loaded script, you have to make them properties of the parent script.

I thought i had using this, or do i need to do it a different way?

script BMMAAppDelegate
   property parent : class "NSObject"
   ---------------------------------------------------------------------
   --- PROPERTYS
   ---------------------------------------------------------------------
   property A : missing value
   property B : missing value
   
on CreateWin_(sender)

set ENT to A's stringValue()
set ENT to ENT as string
-----
set ENW to B's stringValue()
set ENW to ENW as string

set posixPath to current application's NSBundle's mainBundle's pathForResource_ofType_("BMMANUAL", "scpt") as string 
                   set scriptAlias to (posixPath as text) as POSIX file
                   run script scriptAlias
end CreateWin_

You’ve made A and B properties, but you’re not using them in the loaded script.

yeah, thats where i’m stuck, im not sure how to code using a property A, from one script to the next (loaded script)

If you have property A in your ASOC class, and you load a script that says something like “display dialog A”, the second A will reflect the value of the first.

thanks for your patience here Shane but i still cant get my scpt file to see the property from my main script, ive gone back to the beginning and started a new test app.

I must be doing something very wrong here, I have set up a new asoc app
with one button and one text field, created a script that is the below, and bound
button and text field in ib.

script property__a_to_called_scpt_AppDelegate
	property parent : class "NSObject"
	
	property b : "bob"
	
	on TESTBUTTON_(sender)
		
		set posixPath to current application's NSBundle's mainBundle's pathForResource_ofType_("TESTONE", "scpt") as string --FROM A SCPT FILE
		set scriptAlias to (posixPath as text) as POSIX file
		run script scriptAlias
		
	end TESTBUTTON_
	
end script

I have then opened up script editor and added this code

display dialog b

saved the script as TESTONE.scpt , I have then manually added the script
to the Targets Copy Bundle Resource folder, build and run, click on button
no dialog saying bob, to test to make sure i had everything working fine I
put a display dialog “test” into the script built and ran again, dialog appeared,

So my scpt file is not seeing/getting the property b in my main script.

But you’re not loading the script into a variable first. Try something like:

       set myScript to load script scriptAlias
       run myScript

thanks for you input Shane

iv’e been dabbling and now have the code working, along the way I discovered the below, which I am
playing with at the moment, seems faster

on RunScript_(sender)
		
		tell class "test" of current application
			HELLO()
		end tell
		
	end RunScript_
	
	
		on HELLO()
		
		display dialog "hello"
		
	end HELLO