question

chen H avatar image
0 Likes"
chen H asked Ben Wilson converted comment to answer

I create a user command,but it dosen't work in my Flexscript code?

I create a ClientSocketStart command and call it in OnRunStart triggle.

The error as below:

Flexscript Error MODEL:/Tools/OnRunStart Line 12 Unknown command ClientSocketStart being called
Flexscript Error MODEL:/Tools/OnRunStart Line 12 Could not resolve correct operator for = operation. Left side type is Variant&, right type is (invalid)
Flexscript Error MODEL:/Tools/OnRunStart

FlexSim 18.2.2
user commandflexscript error
· 3
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·

@chen H, Is it possible to post the code of the user command and the trigger? Thanks!

0 Likes 0 ·
chen H avatar image chen H Joerg Vogel commented ·
//Here is the code.
//ClientSocketStart(string hostname,num clientport):
string hostname=param(1);
int clientport=param(2);
int client=0;
if(socketinit())
{
 client=clientcreate();
}
int conn=0;
if(client)  //if ok
{
 conn=clientconnect(client,hostname,clientport);
 if(conn)
 {
  print("Connect Succesed");
 }
 else
 {
  print("Connect Failed");
  clientclose(client);
 }
}
else
{
 print("Create Socket Failed!");
}
return client;

//AND triggle:
Object Connect_Source=node("MODEL:/Socket_Conn_Info");
string hostname=Connect_Source.labels["IP"].value;
int clientport=Connect_Source.labels["Port1"].value;
int client=ClientSocketStart(hostname,clientport);

I check it in other models ,it works,but just failed in my current model.
Thank you @Jörg Vogel 


0 Likes 0 ·
Sam Stubbs avatar image Sam Stubbs ♦ chen H commented ·

Are you sure the ClientSocketStart command copied into this model correctly? FlexSim is saying that it can't find the command. Could you send the model?

0 Likes 0 ·

1 Answer

chen H avatar image
0 Likes"
chen H answered

I found the root cause of the problem. The reason is that in the tree structure, the default sorting of Tools folders is 2. I accidentally put the sorting of a node in front of Tools, which makes Usercommand unrecognizable.

Thanks.

5 |100000

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