Script attributes are null

script attributes are null and don’t know why
I mean topSpeed and so on

// Script Attributes

// top vehicle speed
Vehicle.attributes.add('topSpeed', 'number', 10, {
    displayName: 'Top Speed'
}); 

// used to accelerate the vehicle
Vehicle.attributes.add('maxEngineForce', 'number', 1000, {
    displayName: 'Max Engine Force'
}); 

// used for braking
Vehicle.attributes.add('maxBrakingForce', 'number', 30, {
    displayName: 'Max Braking Force'
}); 

// Wheel parameters
Vehicle.attributes.add('suspensionStiffness', 'number', 20, {
    displayName: 'Suspension Stiffness'
});

Vehicle.attributes.add('suspensionDamping', 'number', 2.3, {
    displayName: 'Suspension Damping'
});

Vehicle.attributes.add('suspensionCompression', 'number', 4.4, {
    displayName: 'Suspension Compression'
});

Vehicle.attributes.add('suspensionRestLength', 'number', 0.6, {
    displayName: 'Suspension Rest Length'
});

Vehicle.attributes.add('rollInfluence', 'number', 2, {
    displayName: 'Roll Influence'
});

Vehicle.attributes.add('friction', 'number', 1000, {
    displayName: 'Friction Slip'
});

Vehicle.attributes.add('topRotationSpeed', 'number', 10, {
    displayName: 'Top Rotation Speed'
}); 

Vehicle.attributes.add('torque', 'number', 500, {
    displayName: 'Torque'
});

Hi @grzesiekmq,

Have you created a scriptType on top? Like this:

var Vehicle = pc.createScript('vehicle');

Attribute definitions should come after that.

I have in es6 style
pc.registerScript(Vehicle, 'vehicle');
maybe revert to es5?

That’s not fully complete for what you are trying to do. It will register the new script type to the Playcanvas script registry, but you must pass a reference to an object to use later for declaring your attributes.

1 Like

Here is a more complete example if you want to go with full ES6 classes:

     // define a ES6 script class
    class PlayerController extends pc.ScriptType {
     
          initialize() {
              // called once on initialize
          }
     
          update(dt) {
              // called each tick
          }
     }
     
     // register the class as a script
     pc.registerScript(PlayerController);
     
     // declare script attributes (Must be after pc.registerScript())
     PlayerController.attributes.add('attribute1', {type: 'number'});

I copied vehicle script from space buggy but have

no script objects found

on vehicle script

Can you post a sample project link to take a look?

ok I added

var Vehicle = pc.createScript('vehicle');

and detects the vehicle script object

1 Like

but still not parsing script attributes
here this is scene
https://playcanvas.com/editor/scene/933948

Are you using legacy scripts? That’s the old script format you are trying to parse.

For the correct one consult the manual:

https://developer.playcanvas.com/en/user-manual/scripting/creating-new/

2 Likes