[solved]Change Object Variable via JavaScript

Does anyone know how to change an object’s variable via javascript?
I have an object with a variable id.
but I need to change it via javascript! I tried this:
var obj_1 = runtimeScene.createObject (varGlobal.get (“card_1”). getAsString ());

obj_1.setZOrder (100);
obj_1.setScale (0.49);
// Part of the object variable I want to change.
obj_1.Variables () .get (‘id’). setNumber (001);

but it does not work.

WRONG: --It looks like you should just call obj_1.setVariableNumber(‘id’, 1234)–
https://docs.gdevelop-app.com/GDJS%20Runtime%20Documentation/RuntimeObject.html#.setVariableNumber

Actually you still have to pass in a variable reference… so I jumped the gun on that.

1 Like

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

obj_1.setZOrder(100);
obj_1.setScale(0.49);
obj_1.setLayer(‘Base Layer’);
obj_1.setPosition(341, 336);
obj_1.setVariableNumber(‘id’, 1);

Erro . Do you say referencialo how?
Thanks :confused:

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