Hi.
I am new to Cocos, Cocos Creator and TypeScript. I have a script attached to a sprite node and I am trying to generate a random number when the node is created using the cc.randomRange and cc.randomRangeInt methods. But whatever I try, it is return undefined and in the console I also get an error saying cc.randomRangeInt is not a function.
I tried searching the docs, but it doesn’t actually provide any explanation how to use these methods in practice. Maybe it is common sense but atm I am a total beginner and I have node idea.
This is what I`m trying to do:
@ccclass
export default class NewClass extends cc.Component {
public randomNumber:number
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.randomNumber = cc.randomRangeInt(0,4);
}
start () {
alert(this.randomNumber);
}
update (dt) {
}
}
When I run this, it is alert the value ‘undefined’ and write to the console cc.randomRangeInt is not a function. The reason I do this is because I would like to use the random value in the start() callback function when the node is created. I tried generating the random value all over the place but I always get the same result.
Could anyone please help me and explaining what am I doing wrong or direct me to any article or section of the documentation that could help me?
Thank you.