Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace arguments shown in the JavaScript code blocks by "instanceContainer" #7058

Open
4ian opened this issue Oct 15, 2024 · 1 comment
Open

Comments

@4ian
Copy link
Owner

4ian commented Oct 15, 2024

A JavaScript code block has by default "runtimeScene" as the first argument, then an optional "objects", then eventsFunctionContext.
In practice, this "runtimeScene" is NOT the runtime scene for objects and behaviors. Instead, it's the instance container.

We should probably not encourage using runtimeScene inside a function of a behavior and object. Instead, we could:

  • keep runtimeScene for JS functions in scene events
  • keep only eventsFunctionContext for JS functions in scene events and expose getInstancesContainer() on eventsFunctionsContext. Make an invisible const runtimeScene = this._instanceContainer.getScene() to keep compatibility.
  • (bonus not linked to JS functions) Rework code generation to use eventsFunctionsContext.getInstancesContainer() instead of runtimeScene?
    • If we search "runtimeScene" in all .cpp/.h files, usage is already fairly low.
Repository owner deleted a comment Oct 28, 2024
@Lohithreddy45
Copy link

Solution for "runtimeScene" Refactor
Problem Overview:
Currently, the runtimeScene argument in JavaScript functions is misleading because it actually represents the instance container, not the runtime scene itself. This can lead to confusion, especially in behaviors and objects.

Proposed Solution:
1.Restrict runtimeScene Usage

Keep runtimeScene only for scene events, where it genuinely refers to the runtime scene.
Avoid using runtimeScene in JavaScript functions for behaviors and objects.

  1. Add getInstancesContainer() in eventsFunctionContext

Introduce a method getInstancesContainer() in eventsFunctionContext to access the instance container explicitly.

example:
eventsFunctionContext.getInstancesContainer = function () {
return this._instanceContainer;
};

Modify Code Generation

  1. Update the code generator to replace runtimeScene with getInstancesContainer() where needed.
    If backward compatibility is required, we can introduce
    Like:
    const runtimeScene = this._instanceContainer.getScene();

4.Audit Existing Code
Search for runtimeScene usage in all .cpp and .h files.
Refactor instances where runtimeScene is used incorrectly, replacing it with eventsFunctionContext.getInstancesContainer().

Before Refactor:

function exampleFunction(runtimeScene, objects, eventsFunctionContext) {
const variable = runtimeScene.getVariables().get("myVariable");
}

After Refactor:
function exampleFunction(objects, eventsFunctionContext) {
const instancesContainer = eventsFunctionContext.getInstancesContainer();
const runtimeScene = instancesContainer.getScene();
const variable = runtimeScene.getVariables().get("myVariable");
}

Improvements:

Clarity: Clearer distinction between the instance container and the runtime scene.
Consistency: Standardized approach across behaviors, objects, and scene events.
Backward Compatibility: Older projects won’t break during the transition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants