Javascript Clicker Game Help ,working with objects ,how it shoud behave

Hello forum friends , i started creating a clicker game for my school project .
The project now -
1.click on image get points
2.upgrade clicking value by spending points
3.added another upgrade witch buys you a unit witch generates points /second

So im stuck on number 3 now , i want to add more of them , i was using global variables .But i guess i should use objects ? because i want to create like 10 of them …When you click on diffrent buttons it should change the cost ,points ,points/second for the object.Does a single function with paramaters will be enough ? .I strugling to find the right examples or tutorials .Help me out friends
Have a nice day :slight_smile:

I’m not sure if I understand correctly but perhaps you need an object which exposes methods for setting and getting scores but at the same time hides the score itself. Something like this:

var Upgrade = function(){

    var score = {
        cost: 0,
        points: 0,
        pointsPerSec: 0
    }

    var setScore = function(cost,points,pointsPerSec){
        score.cost = cost;
        score.points = points;
        score.pointsPerSec = pointsPerSec;
    };

    var getScore = function(){
        return score;
    };

    return {
        setScore: setScore,
        getScore: getScore
    }
    }

    var upgrade1 = new Upgrade();
    upgrade1.setScore(10,25,125);
    upgrade1.getScore(); //returns 10,25,125

    var upgrade2 = new Upgrade();
    upgrade2.setScore(120,30,50);
    upgrade2.getScore(); //returns 120,30,50`
2 Likes

Thanks przemoo83 its seems like what i was needed…Im sorry my english is a little bit rusty ,what i needed was a reusable function to update the objects after button click .Thanks again , this gona help me a lot

You may use the example of mine to make yours–just don’t copy it.
https://codepen.io/Glaurung/pen/qBWmPbZ