BJS Editor V4 scripting

Hi @julien-moreau I’ve got a couple of questions regarding editor v4 :slight_smile:
I’m using version 4-rc1 on Windows 10

  1. In my workspace I have several projects which represent individual levels of my game. For example projectA, projectB and projectC Now when I’m switching between those projects I would assume that, when I hit the play-button, the current project which I have switched to will be executed. This is not the case. What I’ve found out so far is that I have to modify the script src/index.ts and adapt import { runScene } from "./scenes/projectA"; and const rootUrl = "./scenes/projectA/"; to the scene I’v switched to so it is executed when hitting the play-button. Now, is there a way to automatically have the correct project executed when switched to without modifying src/index.ts?

  2. I have a bunch of scripts within this projects which are basically always the same. For example script scene.ts is the same for projectA, projectB and projectC. I have to copy this script 3 times for every project which is quite cumbersome if I have to make edits because of that redundancy. Is there a way to share scripts within projects?

Thanks for the great editor. Hopefully you have some advice :slight_smile:

Hey @holger ! Only excellent questions and it will be a pleasure to answer :slight_smile:

For the 1. unfortunately there is no way today to automatically switch. This is in my todolist but I have still not found any elegant solution at the moment. I would like to find a solution without any breaking change. Just created the issue here: Add Way To Automatically Switch Scene When Clicking On The Play Button · Issue #251 · BabylonJS/Editor · GitHub
You’ll stil have to manually switch in your code :frowning:

For the 2. I 100% agree with you and I already started a fix to allow accessing the root folder “src” for all projects. That means, if you have shared components, that you will be able to create a folder named “shared” (for example) and let all your projects accessing this folder. This will also reduce the final bundle size. To follow the progress, I just created the issue here: Give Full Access To "src" Folder In Scripts Assets · Issue #250 · BabylonJS/Editor · GitHub

Both your questions are then bug reports, the 2. will be fixed ASAP :slight_smile: and I’ll try to find a solution for the 1.

Thanks again for these feedbacks!

Thank you @julien-moreau for the lightning fast answers and the created issues :slight_smile:

1 Like

Hey @holger the the reusable scripts across scenes, there will be a breaking change :frowning:
If you decorated your properties in your components (@visibleInInspector, @fromScene, etc.) you’ll have to import from “decorators.ts” instead of “tools.ts”. Because else the imports will be cyclical and you’ll get errors :frowning: .

This shouldn’t be a problem, thanks for the info! :slight_smile:

Hi @julien-moreau I’ve just tested the reuse of scripts in rc2. Works like a champ :slight_smile: Thank you!

1 Like