How do I create an ...
 
Notifications
Clear all

[Solved] How do I create an object using script?

2 Posts
2 Users
1 Reactions
663 Views
0
Topic starter

In "load" event at Scene.Map, I would like to create a simple object in loaded scene. Can I do that? How?
Thanks

1 Answer
1

You should check how the event command work, it implies to change some of the map properties to avoid bugs/side effects. It's in EventCommand/CreateObjectInMap.js:

            let id = ++Scene.Map.current.maxObjectsID;

            let position = Position.createFromVector3(currentState.position);

            let globalPortion = position.getGlobalPortion();

            Scene.Map.current.allObjects[id] = position;

            let newObject = new MapObject(System.MapObject.createFromModelID(this.modelID.getValue(), id), currentState.position);

            if (this.isStockID) {

                Game.current.variables[this.stockID.getValue(true)] = id;

            }

            Game.current.getPortionDatas(Scene.Map.current.id, globalPortion).m.push(newObject);

            Game.current.getPortionDatas(Scene.Map.current.id, globalPortion).min.push(newObject);

            newObject.changeState();

Lizzard Topic starter 06/09/2023 10:31 pm

@wano, it's works very well! You can look at my adapted code, in case anyone has the same question!

Share: