[Solved]CreateObject - Javascript error

I need help with this - I create an object using javascript. But when I start the game he will create several objects.

To avoid this I used onceTrigger to isolate the creation of the object and it works more later when I try to move it with a setPosition.

The game crashes! Does anyone know how to create objects with javascript so that only one is created and then I can move it around the scene?

My code below.

var obj_1 = runtimeScene.createObject(varGlobal.get(“card_1”).getAsString());

obj_1.setLayer(‘Base Layer’);
obj_1.setPosition(341, 336);


In this part I do the obj_1.setPosition but the error. I thought it was the scope of the variable so I declared it outside of OnceTriggers but it still didn’t work.

please help!

If you only want to create the object once and don’t want to use the triggerOnce condition you could create a variable to check.

1 Like

Thank you. Eiklahc.

Still looking for a solution. It seems that the createobject is only created correctly by the visual mode via code and generated several constantly.

1 Like

Is your actions a sub event of your condition? Drag them to the right.

1 Like

I understand what you said, but no. I created a javascript and it is not a subevent. :confused: thanks.

If you don’t set it as a subevent it will keep creating the object,

The point is that I can’t move the object after creating it. I use setPosition and nothing. Now I’m trying to change a variable in the created object - but it’s an error. I thought about changing a variable id to move it out of javascript because even though I was successful in creating the object afterwards, it doesn’t move. - if I try to move it crashes the game.

Why are you using JS? It’s easier using Conditions and Actions.
To move it in JS you have to assign keys and variables for speed and directions.

1 Like

I am using javascript because I want to send information from one scene to another scene with the items that will be used in lvl.

I need to change an object variable - do you know how I do it using javascript? I tried :

obj_1.Variables (). get (‘id’). setNumber (001);

but the error if I change the id of the object I can manipulate it outside the code.

Not sure, but I think is:
var obj_1.id = 001

1 Like

I did a behavior to change the id! object variable. Thanks.:smiley: