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 ·
  1. //Here is the code.
  2. //ClientSocketStart(string hostname,num clientport):
  3. string hostname=param(1);
  4. int clientport=param(2);
  5. int client=0;
  6. if(socketinit())
  7. {
  8. client=clientcreate();
  9. }
  10. int conn=0;
  11. if(client) //if ok
  12. {
  13. conn=clientconnect(client,hostname,clientport);
  14. if(conn)
  15. {
  16. print("Connect Succesed");
  17. }
  18. else
  19. {
  20. print("Connect Failed");
  21. clientclose(client);
  22. }
  23. }
  24. else
  25. {
  26. print("Create Socket Failed!");
  27. }
  28. return client;
  29.  
  30. //AND triggle:
  31. Object Connect_Source=node("MODEL:/Socket_Conn_Info");
  32. string hostname=Connect_Source.labels["IP"].value;
  33. int clientport=Connect_Source.labels["Port1"].value;
  34. int client=ClientSocketStart(hostname,clientport);
  35.  
  36. I check it in other models ,it works,but just failed in my current model.
  37. Thank you @Jörg Vogel
  38.  
  39.  
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.