Cannot set playerName in a called routine #676

Open
opened 2026-02-20 10:19:40 -05:00 by deekerman · 1 comment
Owner

Originally created by @96LawDawg on GitHub (Feb 15, 2023).

This does not work:

 "clickRoutine": [
    {
      "func": "CALL",
      "routine": "testRoutine"
    }
  ],
  "testRoutine": [
    "var playerName = 'TestMe'"
  ]
Originally created by @96LawDawg on GitHub (Feb 15, 2023). This does not work: ``` "clickRoutine": [ { "func": "CALL", "routine": "testRoutine" } ], "testRoutine": [ "var playerName = 'TestMe'" ] ```
Author
Owner

@robartsd commented on GitHub (Feb 16, 2023):

I think this is because the called routine has its own namespace. It inherits copies of variables defined in the calling routine, but changes made in the calling routine get thrown out when the routine terminates. The special playerName and playerColor variables are only updated if they have changed at the end of the root routine. Of course it is possible to collect these in a called routine, but they would need to be passed back to the calling routine (in the result variable) to be set.

 "clickRoutine": [
    {
      "func": "CALL",
      "routine": "testRoutine",
      "variable": "playerName"
    }
  ],
  "testRoutine": [
    "var result = 'TestMe'"
  ]
@robartsd commented on GitHub (Feb 16, 2023): I think this is because the called routine has its own namespace. It inherits copies of variables defined in the calling routine, but changes made in the calling routine get thrown out when the routine terminates. The special playerName and playerColor variables are only updated if they have changed at the end of the root routine. Of course it is possible to collect these in a called routine, but they would need to be passed back to the calling routine (in the result variable) to be set. ``` "clickRoutine": [ { "func": "CALL", "routine": "testRoutine", "variable": "playerName" } ], "testRoutine": [ "var result = 'TestMe'" ] ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/virtualtabletop#676
No description provided.