<?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: how to create a function and be able to call it for returning a value. in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600091#M94011</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;
 if i would like to send couple of values, how to i mention that in code section?
&lt;/DIV&gt;</description>
    <pubDate>Tue, 25 Jul 2023 20:23:01 GMT</pubDate>
    <dc:creator>athodupunoori</dc:creator>
    <dc:date>2023-07-25T20:23:01Z</dc:date>
    <item>
      <title>how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600089#M94009</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 21.1.5 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi, i would like to create a function using flexscript, where when i call the function, it has to return the some value according to the calculation i put inside the function.&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
 &lt;P&gt;Example&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1690314752039.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1518589i62CB1E50A32FEC11/image-size/large?v=v2&amp;amp;px=999" role="button" title="1690314752039.png" alt="1690314752039.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
 &lt;P&gt;here i am just trying to create a addition function where if i send two values, it has to save that number at specified table and return me the added value "C" for the variable "dd".&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 19:55:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600089#M94009</guid>
      <dc:creator>athodupunoori</dc:creator>
      <dc:date>2023-07-25T19:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600090#M94010</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi &lt;A rel="user" href="https://answers.flexsim.com/users/34977/ankitht.html" nodeid="34977"&gt;@Ankith T&lt;/A&gt;! You can add a function by going to Toolbox -&amp;gt; Modeling Logic -&amp;gt; User Commands. This will allow you to make a little function for your model. You can add the code at the bottom. Here's a link to the documentation for the tool: &lt;A href="https://docs.flexsim.com/en/23.1/Reference/Tools/UserCommands/UserCommands.html#app" target="test_blank"&gt;https://docs.flexsim.com/en/23.1/Reference/Tools/UserCommands/UserCommands.html#app&lt;/A&gt;&lt;/P&gt;
 &lt;P&gt;Let me know if you have any follow up questions!&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 20:13:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600090#M94010</guid>
      <dc:creator>julie_weller</dc:creator>
      <dc:date>2023-07-25T20:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600091#M94011</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 if i would like to send couple of values, how to i mention that in code section?
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 20:23:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600091#M94011</guid>
      <dc:creator>athodupunoori</dc:creator>
      <dc:date>2023-07-25T20:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600092#M94012</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Here's an example for what you want to do:&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1690316904328.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1518584iA33C411C5FC4C9E3/image-size/large?v=v2&amp;amp;px=999" role="button" title="1690316904328.png" alt="1690316904328.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1690316917791.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1518585i38E31FF7FAA949A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="1690316917791.png" alt="1690316917791.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 20:28:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600092#M94012</guid>
      <dc:creator>julie_weller</dc:creator>
      <dc:date>2023-07-25T20:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600093#M94013</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thank you, that cleared my doubt. But what if i would like to return multiple variables. such as string and double. where string tells me its an addition and double tells me the value of addition.
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 21:18:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600093#M94013</guid>
      <dc:creator>athodupunoori</dc:creator>
      <dc:date>2023-07-25T21:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600094#M94014</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You can return an array or map - the latter allowing you to access the result's attribute/key values using dot notation.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 21:20:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600094#M94014</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2023-07-25T21:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600095#M94015</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;To do something like that you could create 2 functions, one that tells you the string and one that gives you the double. You could update the table with both of those values. You could write to a Global Variable. However you can only return 1 value, just as in C++&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 21:21:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600095#M94015</guid>
      <dc:creator>julie_weller</dc:creator>
      <dc:date>2023-07-25T21:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600096#M94016</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Or as Jason said, you can update something that already consists of multiple elements, but they need to be a unit
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Jul 2023 21:22:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600096#M94016</guid>
      <dc:creator>julie_weller</dc:creator>
      <dc:date>2023-07-25T21:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600097#M94017</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 can you send here a sample code, showing how to return values in array and how to access after returning.
&lt;/DIV&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:03:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600097#M94017</guid>
      <dc:creator>athodupunoori</dc:creator>
      <dc:date>2023-07-26T15:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600098#M94018</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Here's the map version:&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/71702-mapresultfromcommand.fsm" target="_blank"&gt;mapResultFromCommand.fsm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1690385243223.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1518587iA0B970EE749C1AE8/image-size/large?v=v2&amp;amp;px=999" role="button" title="1690385243223.png" alt="1690385243223.png" /&gt;&lt;/span&gt;customFunc code:&lt;/P&gt;&lt;PRE&gt;/**Custom Code*/
Map result;
result["calcValue"]=param(1)+param(2);
result["operation"]="Addition";
return result;&lt;/PRE&gt;&lt;P&gt;Test script:&lt;/P&gt;&lt;PRE&gt;var result=customFunc(5,9);
print(result.calcValue);
print(result.operation);&lt;/PRE&gt;&lt;P&gt;Console output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Image.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1520158i4A308B09265BCED1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Image.png" alt="Image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The version with arrays is just:&lt;/P&gt;&lt;PRE&gt;/**Custom Code*/
Array result;
result.push(param(1)+param(2));
result.push("Addition");
return result;&lt;/PRE&gt;&lt;P&gt;with test script:&lt;/P&gt;&lt;PRE&gt;var result=customFunc(5,9);
print(result[1]);
print(result[2]);&lt;/PRE&gt;&lt;P&gt;If you want to use all the array operators and methods then you need to cast it as an array not var in the test script like this:&lt;/P&gt;&lt;PRE&gt;Array result=customFunc(5,9);
print(result.pop());
print(result.pop());
print(result.length);&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:26:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600098#M94018</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2023-07-26T15:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a function and be able to call it for returning a value.</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600099#M94019</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thank you so much, this is what exactly i needed.
&lt;/DIV&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:44:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-create-a-function-and-be-able-to-call-it-for-returning-a/m-p/13600099#M94019</guid>
      <dc:creator>athodupunoori</dc:creator>
      <dc:date>2023-07-26T15:44:26Z</dc:date>
    </item>
  </channel>
</rss>

