question

Jan avatar image
0 Likes"
Jan asked Jan commented

custom code object issue

Model custom code.fsmHello, I am currently writing a code that reads the label "Entrance" which holds the Floorstorage number and then adds a label with one of the two buffers that are associated to the Floorstorage to the token. I always get the Error code:

Flexscript Error MODEL:/Tools/ProcessFlow/ProcessFlow5/Custom Code>variables/codeNode Line 6 syntax error, unexpected '{'

Could not finish parsing because of previous errors.


Is this code even able to do my operation? I am currently just trying out the coding feature.



/**Custom Code*/

// Get the name of the current floor storage

string storageName = label(current, "Entrance");


// Define the buffers associated with each floor storage

object bufferDict = {

"FloorStorage 461": ["_461 Buffer", "_461 Buffer1"],

"FloorStorage 460": ["_460 Buffer", "_460 Buffer1"],

"FloorStorage 462": ["_462 Buffer", "_462 Buffer1"],

"FloorStorage 459": ["_459 Buffer", "_459 Buffer1"],

"FloorStorage 458": ["_458 Buffer", "_458 Buffer1"],

"FloorStorage 457": ["_457 Buffer", "_457 Buffer1"]

};


// Find the index of the current floor storage in the bufferDict array

int storageIndex = find(array(bufferDict), storageName);


// Select a random buffer for the current floor storage

int bufferIndex = rand(1, 2);

string selectedBuffer = bufferDict[storageName][bufferIndex];


// Print the selected buffer name to the console

traceln("Selected Buffer for " + storageName + ": " + selectedBuffer);


// Add a label to the token with the selected buffer name

token.label(selectedBuffer);


// Return the selected buffer as a node reference

return node(current, selectedBuffer);



Thank you all for your help in Advance!

FlexSim 23.0.4
labelscodeobject
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jacob W2 avatar image Jacob W2 ♦ commented ·

Hi @Jan,

Do you have a model that you can share? It is a lot easier to debug code, and find potential issues while using the model.

Proprietary models can be posted as a private question visible only to FlexSim U.S. support staff. You can also contact your local FlexSim distributor for phone or email help.

0 Likes 0 ·
Jan avatar image Jan Jacob W2 ♦ commented ·
Hi Jacob,


Sorry for that.

I added a version of my model.

0 Likes 0 ·

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Jan commented

I'm not sure what programming language you are acquainted with, but most of what you typed is not valid syntax and/or commands in FlexSim.

Under the following link you can find an introduction to coding in FlexSim. The full class and command reference is also available a couple entries further down in the menu on the left.

https://docs.flexsim.com/en/23.0/Reference/CodingInFlexSim/WritingLogic/WritingLogic.html

Here is what the code would look like in FlexScript:

Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);

// Get the name of the current floor storage
string storageName = token.Entrance.name;

// Define the buffers associated with each floor storage
Map bufferMap;
bufferMap["FloorStorage 462"] = ["_462 Buffer2", "_462 Buffer3"];
bufferMap["FloorStorage 461"] = ["_461 Buffer2", "_461 Buffer3"];
bufferMap["FloorStorage 460"] = ["_460 Buffer2", "_460 Buffer3"];
bufferMap["FloorStorage 459"] = ["_459 Buffer2", "_459 Buffer3"];
bufferMap["FloorStorage 458"] = ["_458 Buffer2", "_458 Buffer3"];
bufferMap["FloorStorage 457"] = ["_457 Buffer2", "_457 Buffer3"];

// Select a random buffer for the current floor storage
int bufferIndex = duniform(1, 2, getstream(activity));
string selectedBuffer = bufferMap[storageName][bufferIndex];

// Print the selected buffer name to the console
print("Selected Buffer for " + storageName + ": " + selectedBuffer);

// Add a label to the token with the selected buffer name
token.labels.assert("selectedBuffer").value = Model.find(selectedBuffer);

model-custom-code_1.fsm


· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jan avatar image Jan commented ·

Thank you so much @Felix Möhlmann !

This really made my day way easier!

And yes I messed up the synatx real bad ! :D

0 Likes 0 ·