Failed to get the default value of speed in class "newclass"

i was following a tutorial i follow it like a book and i got an error which i have no idea what could have cause it
it says:
Failed to get default value of “speed” in class “NewClass”. If using TypeScript, you also need to pass in the “default” attribute required by the “property” decorator.

the code i used:

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

@property
speed: number = 10 ;

     onLoad () {

     }

    start () {

    }

     update (dt) {
         this.node.setPosition(this.node.position.x+this.speed*dt,this.node.position.y);
        if(this.node.position.x>this.node.parent.width)
        {
            this.node.setPosition(0,this.node.position.y);
        }


         
     }
}

not only that but i am also unable to set the value in cocos creator as it should
it should appear a box where i set the value for each individual zombies but the box is not even there.

please explain me why i got this error, what could have caused it and how to fix it.
Thanks!!


I tried your code in 2.4.9 and it didn’t report you this error. Under what circumstances do you report the error?

Hi, if the problem is solved, please reply.

i updated to 3.5.1 and wrote the properties with different way and it worked
i wrote em as:

@property({type:Number})

public speed: number = 10;

it can be closed now…

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.