<?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: Is the scope of current from a user command the calling object? in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500894#M16110</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/7327/michaelh5.html" nodeid="7327"&gt;@Michael&lt;/A&gt;, &lt;A rel="user" href="https://answers.flexsim.com/users/461/joerg.v.html" nodeid="461"&gt;@Jörg Vogel&lt;/A&gt; current is not in scope in a usercommand. current points to the object the code is written on but a usercommand is not defined on an object and so current doesn't exist. Is also easy to check by creating a usercommand and do anything with current and use the debugger to see the value if you step through the code.&lt;/P&gt;&lt;P&gt;If you want to use current you have to pass it in as an argument and get it out with param() in the usercommand.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="autotaguser-autocomplete-box"&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Mar 2018 08:08:58 GMT</pubDate>
    <dc:creator>SCHamoen</dc:creator>
    <dc:date>2018-03-07T08:08:58Z</dc:date>
    <item>
      <title>Is the scope of current from a user command the calling object?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500893#M16109</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 16.1.2 ]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/7327/michaelh5.html" nodeid="7327"&gt;@Michael&lt;/A&gt; asked the question:&lt;/P&gt;&lt;P&gt;When calling a user command from an object's trigger's custom code, does the "current" in the user command scope still reference the original object that was triggered? Or should we pass in a reference to the object as an argument to the user command?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 05:20:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500893#M16109</guid>
      <dc:creator>joerg_vogel_HsH</dc:creator>
      <dc:date>2018-03-07T05:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is the scope of current from a user command the calling object?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500894#M16110</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/7327/michaelh5.html" nodeid="7327"&gt;@Michael&lt;/A&gt;, &lt;A rel="user" href="https://answers.flexsim.com/users/461/joerg.v.html" nodeid="461"&gt;@Jörg Vogel&lt;/A&gt; current is not in scope in a usercommand. current points to the object the code is written on but a usercommand is not defined on an object and so current doesn't exist. Is also easy to check by creating a usercommand and do anything with current and use the debugger to see the value if you step through the code.&lt;/P&gt;&lt;P&gt;If you want to use current you have to pass it in as an argument and get it out with param() in the usercommand.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="autotaguser-autocomplete-box"&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 08:08:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500894#M16110</guid>
      <dc:creator>SCHamoen</dc:creator>
      <dc:date>2018-03-07T08:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is the scope of current from a user command the calling object?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500895#M16111</link>
      <description>&lt;P&gt;
	And here is the technical answer, in case anyone wants the details &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;
	If you open up the code of any trigger, you will see that &lt;EM&gt;current&lt;/EM&gt; is defined as&lt;/P&gt;
&lt;PRE&gt;Object current = ownerobject(c);
&lt;/PRE&gt;&lt;P&gt;
	The &lt;EM&gt;c&lt;/EM&gt; variable is like a "magic" variable that always* points at the currently executing code. For the entry trigger of a queue for example, this is the &lt;EM&gt;entrytrigger&lt;/EM&gt; node in the Queue's variables section, e.g. /Queue1&amp;gt;variables/entrytrigger. The &lt;EM&gt;ownerobject&lt;/EM&gt; function basically strips of the 'go into the variables part' after the &lt;EM&gt;&amp;gt;&lt;/EM&gt; and gives you the queue object back. &lt;/P&gt;&lt;P&gt;
	In a user command, you can also access the &lt;EM&gt;c&lt;/EM&gt; variable, and it will point at the place where the User Command code is stored, e.g. /Tools/UserCommands/TestCommand/code. It doesn't matter whether you call the user command from a Script Window, User Event or other trigger, &lt;EM&gt;c&lt;/EM&gt; will always be the user command's &lt;EM&gt;code&lt;/EM&gt; node. So even if you copied the line that determines &lt;EM&gt;current&lt;/EM&gt; literally to your user command, you would not get the expected result: &lt;/P&gt;
&lt;PRE&gt;// c is /Tools/UserCommands/TestCommand/code
Object current = ownerobject(c);
// current is now... MAIN:/project/model !
&lt;/PRE&gt;&lt;P&gt;
	As &lt;A rel="user" href="https://answers.flexsim.com/users/193/steven.h.html" nodeid="193"&gt;@steven.hamoen&lt;/A&gt; already answered, the way around this is by passing the current from the object trigger as an argument into your usercommand, &lt;/P&gt;
&lt;PRE&gt;// In the on entry trigger
Object item = param(1);
Object current = ownerobject(c);
int port = param(2);
TestCommand(current);
&lt;/PRE&gt;&lt;P&gt;
	and then getting it out in the user command by&lt;/P&gt;
&lt;PRE&gt;// In the user command
Object current = param(1);
&lt;/PRE&gt;&lt;P&gt;&lt;SMALL&gt;
	* Actually there are some subtleties, such as when executing event functions.
&lt;/SMALL&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 09:49:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-the-scope-of-current-from-a-user-command-the-calling-object/m-p/13500895#M16111</guid>
      <dc:creator>mischa_spelt</dc:creator>
      <dc:date>2018-03-07T09:49:06Z</dc:date>
    </item>
  </channel>
</rss>

