<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Maxscript: function not recognised by callbacks.addScript in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631829#M8828</link>
    <description>&lt;P&gt;Generally, scripts are executed at startup when located in one of these folders. Notice the choice of either install root, or your local app data.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;C:\Program Files\Autodesk\3ds Max 2019\stdplugs\stdscripts&lt;/LI&gt;
&lt;LI&gt;C:\Program Files\Autodesk\3ds Max 2019\scripts\Startup&lt;/LI&gt;
&lt;LI&gt;C:\Users\ (username) \AppData\Local\Autodesk\3dsMax\2019 - 64bit\ENU\scripts\startup&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There are various tricks and other options, but those are the basics.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If you do not want a script running at startup, then you can define the struct whenever your script is run, and skip past the initialization later, if the script is run a second time. See below for an example.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And yes! I would like to (eventually) write a tutorial going into more depth.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Michaelson Britt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;global myScope

-- Define the scope when first used (it's initially undefined)
if myScope==undefined do
(
	-- Define the struct's type (this doesn't create data yet)
	-- Notice both data and methods here, and methods can use "this" value
	-- Notice data members can have default values here
	struct MyScopeStruct (
		fn myFunc param =
		(
			messagebox ("Hello, "+param+" My data is "+(this.myData as string))
		),
		myData = 1
	)

	-- Create an instance of the struct
	-- Notice member data can optionally be set
	myScope = MyScopeStruct myData:2

	-- Test it out, set member data and call methods
	myScope.myData = 3
	myScope.myFunc "world!"
)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Mar 2019 10:14:57 GMT</pubDate>
    <dc:creator>michaelsonbritt</dc:creator>
    <dc:date>2019-03-02T10:14:57Z</dc:date>
    <item>
      <title>Maxscript: function not recognised by callbacks.addScript</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8617166#M8825</link>
      <description>&lt;P&gt;I'm trying to get a layerchange to trigger events and i had it working earlier but now when i rewrote the callback i get&amp;nbsp; -- Type error: Call needs function or class, got: undefined&lt;/P&gt;
&lt;P&gt;It works when i run the code in the listener but not when run as .ms, so i'm guessing it has to do with the function not set up correctly ?.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MacroScript NewTest&lt;BR /&gt;Category: "ScriptTests"&lt;BR /&gt;(&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn RunThis = &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "problem solved!"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )--end fn&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn disable_event = (callbacks.removescripts #nodeLayerChanged id:#TestID)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn enable_event = (callbacks.addScript #nodeLayerChanged "RunThis()" id:#TestID)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; disable_event()&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; enable_event()&lt;/P&gt;
&lt;P&gt;)--end script&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Sun, 24 Feb 2019 12:09:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8617166#M8825</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-02-24T12:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Maxscript: function not recognised by callbacks.addScript</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8617846#M8826</link>
      <description>&lt;P&gt;This looks like a scoping problem.&amp;nbsp; Try defining the RunThis() function as global per the script below.&amp;nbsp; Notice that global is used before the RunThis function is defined, so that when defined it's setting the global value instead of creating a new local.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the callback triggers, it's running in the global scope at that time.&amp;nbsp; It tries to execute the function RunThis(), but there is no such function because that was a local variable inside the MacroScript definition of NewTest.&amp;nbsp; You could explicitly make the RunThis() global.&amp;nbsp; Or, maybe a better approach more generally, you could create a startup script which defines a struct containing all your various utility functions as members.&amp;nbsp; Then your MacroScripts can access them as "myGlobalStruct.myFunction()" without creating too much global namespace pollution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Michaelson Britt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;macroScript NewTest
Category: "ScriptTests"
(
	global RunThis
	fn RunThis =
	(
	print "problem solved!"
	)--end fn

	fn disable_event = (callbacks.removescripts #nodeLayerChanged id:#TestID)
	fn enable_event = (callbacks.addScript #nodeLayerChanged "RunThis()" id:#TestID)
	disable_event()
	enable_event()

)--end script&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Feb 2019 00:38:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8617846#M8826</guid>
      <dc:creator>michaelsonbritt</dc:creator>
      <dc:date>2019-02-25T00:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Maxscript: function not recognised by callbacks.addScript</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631217#M8827</link>
      <description>&lt;P&gt;Great help!&lt;/P&gt;
&lt;P&gt;I was suspecting this was the issue but for some reason i didn't think you could make functions global this easy .&lt;/P&gt;
&lt;P&gt;I've heard many talk about a struct startup-file and i will be looking into this, but is there a way to not have to put it into the startupfolder?.&lt;/P&gt;
&lt;P&gt;I work on multiple workstations and like to have all the scripts i use in one folder in the cloud to easy be able to update them .&lt;/P&gt;
&lt;P&gt;I've looked into filein and include and filein looked most promising. Most of all i would like to find a tutorial about how to organise complex scripts and good practice but no luck so far.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 20:51:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631217#M8827</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-01T20:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Maxscript: function not recognised by callbacks.addScript</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631829#M8828</link>
      <description>&lt;P&gt;Generally, scripts are executed at startup when located in one of these folders. Notice the choice of either install root, or your local app data.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;C:\Program Files\Autodesk\3ds Max 2019\stdplugs\stdscripts&lt;/LI&gt;
&lt;LI&gt;C:\Program Files\Autodesk\3ds Max 2019\scripts\Startup&lt;/LI&gt;
&lt;LI&gt;C:\Users\ (username) \AppData\Local\Autodesk\3dsMax\2019 - 64bit\ENU\scripts\startup&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There are various tricks and other options, but those are the basics.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If you do not want a script running at startup, then you can define the struct whenever your script is run, and skip past the initialization later, if the script is run a second time. See below for an example.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And yes! I would like to (eventually) write a tutorial going into more depth.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Michaelson Britt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;global myScope

-- Define the scope when first used (it's initially undefined)
if myScope==undefined do
(
	-- Define the struct's type (this doesn't create data yet)
	-- Notice both data and methods here, and methods can use "this" value
	-- Notice data members can have default values here
	struct MyScopeStruct (
		fn myFunc param =
		(
			messagebox ("Hello, "+param+" My data is "+(this.myData as string))
		),
		myData = 1
	)

	-- Create an instance of the struct
	-- Notice member data can optionally be set
	myScope = MyScopeStruct myData:2

	-- Test it out, set member data and call methods
	myScope.myData = 3
	myScope.myFunc "world!"
)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 10:14:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631829#M8828</guid>
      <dc:creator>michaelsonbritt</dc:creator>
      <dc:date>2019-03-02T10:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Maxscript: function not recognised by callbacks.addScript</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631905#M8829</link>
      <description>&lt;P&gt;Got structs to work,thanks.&lt;/P&gt;
&lt;P&gt;What wasn't clear in maxscript help was that functions and vars inside structs is separated with comma(,).&lt;/P&gt;
&lt;P&gt;Secondly, why are you using a var (myScope) to point to the struct instead of calling and making MyScopeStruct global directly?.&lt;/P&gt;
&lt;P&gt;After solving my initial problem i changed the functions to something else then a simple text print. constructors crash max to desktop without warning, se example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;macroScript NewTest&lt;BR /&gt;Category: "TestScripts"&lt;BR /&gt;(&lt;/P&gt;
&lt;P&gt;global RunThis&lt;BR /&gt;fn RunThis =&lt;BR /&gt;(&lt;BR /&gt;sphere()&lt;BR /&gt;)--end fn&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;fn disable_event = (callbacks.removescripts #nodeLayerChanged id:#TestID)&lt;BR /&gt;fn enable_event = (callbacks.addScript #nodeLayerChanged "(RunThis())" id:#TestID)&lt;/P&gt;
&lt;P&gt;disable_event()&lt;BR /&gt;enable_event()&lt;/P&gt;
&lt;P&gt;)--end script&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only thing working is manipulation and string prints.&lt;/P&gt;
&lt;P&gt;I've created a new topic in the forum here : &lt;A href="https://forums.autodesk.com/t5/3ds-max-programming/maxscript-callbacks-addscript-nodelayerchanged-fn-calling/td-p/8631902" target="_blank"&gt;https://forums.autodesk.com/t5/3ds-max-programming/maxscript-callbacks-addscript-nodelayerchanged-fn-calling/td-p/8631902&lt;/A&gt; as i think this a new separate problem&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 11:41:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-function-not-recognised-by-callbacks-addscript/m-p/8631905#M8829</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-02T11:41:00Z</dc:date>
    </item>
  </channel>
</rss>

