Math - Adding Scores

Hey Folks…
I’m just getting started with JS and curious how one would calculate the total of (5) different variables. I have a game that rewards points for acquiring things. Things are on a separate timeline, and once they have been acquired, points are awarded, then players may choose their next task.

I could force players on a linear path and just add them together (eg; task one = 500 points, task two is 750 points, etc), but we allow players non-linear gameplay.

Would this be done with some form of database or through JS and maybe an Array?
Thanks in advance for any suggestions.

Very basic example.

You can use the hypedocument.customdata API

scores.hype 2.zip (22.1 KB)

For more detail on hypedocument.customdata API see

hypeDocument.customData quick examples of setting and getting data

1 Like

Edit.
I adjusted the example above to use one function, also to show that you do not need to initially declare the hypedocument.customdata key-values.

i.e I had an init function on scene Prepare for display to declare the hypedocument.customdata.xxx before we used them.
No need to do that. You can declare them at first use.

Hey Mark, thank you very much.
As mentioned in my initial post - pretty much a JS noob, but I have been working my way through a couple Lynda.com courses, and as many examples as I can find. Doing my best to follow your code… which isn’t working out too well yet… lol.

While I very much appreciate your script, I need to edit it so when players complete a task, they tap a ‘completed’ button and are awarded X points. They will perform another task… it’s kind of a treasure hunting game… and when that task is completed, they tap and those task points are added to the current balance. Each level has several different tasks that can be completed in non-linear order.

I am still working out all the design elements and layout, but thinking in advance for what we need for scoring.

I also downloaded an earlier countdown timer you posted… that too has my wee JS brain spinning :slight_smile:

Thanks again.

1 Like