Script Attribute Arguments


#1

Hey Guys :slightly_smiling_face:

I have various problems with script attributes and I hope that you can help me.
First of all, which page of the documentation is the correct/up-to-date one?

My guess is the second one, since various names, like ‘enum’ are called as documented there, instead of ‘enumerations’, like it is on the first link.

Seconds, and this is my main question, some of the arguments don’t seem to work, or the documentation doesn’t seem to provide enough information to make them work. I tried adding a simple slider to my stepNumber attribute. The arguments title, type, default, min and max work as expected, but the arguments step and precision don’t. They just don’t seem to do anything.

AttributeTests.attributes.add('stepNumber', {
    title: 'Steping Number',
    type: 'number',
    default: 5,
    min: 1,
    max: 9,
    step: 1,
    precision: 2,
});

I tried various combinations of these arguments (in case they would cancel eachother out), tried it in different projects, experimented with the order of these arguments and of course their values, but nothing seems to change.

Capture

Can anyone help me and provide me with insight? Thanks


#2

@vaios Is this something you can help with? It looks like to be more todo with the editor code than engine?


#3

Hi

There are 2 script systems. Your first link refers to the legacy script system (https://developer.playcanvas.com/en/api/pc.script.html).

The new script system uses script assets and is the one you should use. The second link is the one that you should refer to (https://developer.playcanvas.com/en/api/pc.ScriptAttributes.html).

The step and precision fields do not seem to be used in the new system. If needed we could add support for those two fields. I did notice precision is documented which is wrong.


#4

Actually we just deployed an update which should now support precision and step.


#5

Thanks for the help. Seems that reading a documentation thoroughly would be wise, since I didn’t notice, that one has to use the arrow keys to increment a value by the step :sweat_smile: I thought the step value would also define by how much the value will change when using a slider. I hoped this way it would be possible to simulate a real integer. But i guess i can also do that by setting the precision to 0.

There are still some issues with both precision and step though. When adding the argument to the attribute and parsing the script, it works as intented. If I then change their value (e.g.: changing step: 2 to step: 3) and parse the script again, it has no effect on the script (value still gets incremented by 2). Only after refreshing the browser tab, the new values are accepted.


#6

You do not have to refresh for the changes to take effect but you do have to de-select and re-select the entity at the moment.