Copy link to clipboard
Copied
[INTRO]
I've been writing codes for a year now, and many people have told me that I'm the worst programmer there is. I know the basics, but somehow I missed some of the fundamentals and the concepts, and now I'm stucked at my game development. I'm using Javascript in Adobe Animate to create a very very tiny game that only involves clicking with mouse.
I followed a tutorial posted in this is site (this one) . I didn't copy the whole thing tho, I just trying to learn the basics and methods he's using. Now, there's a part in that tutorial that explains a bit about prototype. I have no idea what that is, and I just used it ignorantly as a way to bridge one function to another.
[CODES]
I have three scripts thatis distributed in three layers:
function Main(){
this.Litter = new Litter();
this.Money = new Money();
litterP = 0;
moneyP = 0;
createJS.Ticker._addEventListener("tick", this.update.bind(this));
}
Main.prototype.update = function(evt){
this.litterP=this.Litter.update();
this.moneyP=this.Money.update();
console.log("Main::update()");
}
----------------------------
function Money(){
this._moneyP = 0;
}
Money.prototype.update = function()
{
return this._moneyP;
}
Money.prototype.getMoneyP = function(){
this._moneyP=this._moneyP+1;
exportRoot.money_1.visible=false;
exportRoot.moneyP_text.text=this._moneyP;
}
exportRoot.money_1.addEventListener("click", Money.prototype.getMoneyP.bind(this));
--------------------------------
function Litter(){
this._litterP=0;
}
Litter.prototype.update=function()
{
return this._litterP;
}
Litter.prototype.getLitterP = function(){
this._litterP=this._litterP_litterP+1;
exportRoot.lit_1.visible = false;
exportRoot.litterP_text.text=this._litterP;
}
exportRoot.lit_1.addEventListener("click", Litter.prototype.getLitterP.bind(this));
[PROBLEMS]
Everytime the instance called "lit_1", the value of litter_1 should be added by 1, and then its value should be printed in a textbox called "litterP_text". When I tried to click, instead of displaying "1", it displays "NaN". It seems like the value of litter_1 is undefined. The same thing happens to the money_1.
How can I solve this?
[QUESTIONS]
[Note]
I've frustrated many people with my code, so before you complain, I would to apologize. Thank you for reading.
Have something to add?