Skip to content
← Back to Community
Make a highscore visible to all players of a game?
Profile icon
EthanBlesch

I have an infinite runner game I coded that my classmates compete for high scores on, is there a way I could make high scores visible to all? basically make select variables universal across all users and update their values on page load

Voters
Profile icon
EthanBlesch
Comments
hotnewtop
Profile icon
BrysonVan1

You’ll need a database of some sort. I would recommend using another repl and setting up a endpoint to get and save the score or you could use Firebase Firestore by Google and not worry about the backend stuff. I’ve used both so reply if you need any help

Profile icon
EthanBlesch

@BrysonVan1 wuuuuuuuut? I know NOTHING about the innards of the web, PHP, HTML forms, etc. How can I do this? My guess is I use something to modify a JSON file permanently, but IDK

Profile icon
btfuss

@EthanBlesch Run HTML on a node.js server
Connect the nodejs to something (if you do a local database it resets when you go into the repl)

Profile icon
EthanBlesch

@btfuss wuuuuuuuuuuuuuuuuuuuuuut

Profile icon
BrysonVan1

@EthanBlesch I'm going to put together a repl that shows what we mean... one moment

Profile icon
EthanBlesch

@BrysonVan1 thanks!

Profile icon
BrysonVan1

@EthanBlesch Here's what I came up with: https://replit.com/@BrysonVan1/UnripeSnivelingCategories. I tried to add some comments to make it a little simpler but overall the code isn't too complicated. It's written in Javascript so there's no need to learn another language.

Profile icon
EthanBlesch

@BrysonVan1 so what would this look like as pseudocode?

Profile icon
EthanBlesch

@BrysonVan1 I don't know a LOT of these keywords, so what this does step by step would be great. I know NOTHING besides variables, functions, object literals, DOM, arrays, etc, nothing about getting other files or databases, get, send, set, query, about 95% of code used in this, it might as well be a new language, could you send me the MDN documentation for the methods this uses?

Profile icon
EthanBlesch

@BrysonVan1 Ok, 2 hours of reverse engineering and google searching later, I sort of understand. This code saves the value 1 under the key score to the repl.it database, but I don't know how I can insert something like this into my JS file.

Profile icon
BrysonVan1

@EthanBlesch I’ll put together an explanation for all this later, can’t right now.

Profile icon
EthanBlesch

@BrysonVan1 Ok, sounds good. Thank you SO much. Not too often I can find someone to help me out without getting annoyed with how little I know about what I'm trying to code, which is while justified in every way, often makes it difficult to learn new skills.

Profile icon
BrysonVan1

@EthanBlesch So, the confusing thing about Node.JS is that’s it’s totally separate from Client side JS. The code I put together creates a route for your code to reference, so whenever you need the high score, use fetch() (look it up on mdn) to get the score and show it using html Canvas text.To merge the two projects, put your files all in the public folder in the repl I made. ( you will need to change your link and script tags with a / before the file path) For instance: “script.js” -> “/script.js” (do the same for CSS)

Profile icon
EthanBlesch

@BrysonVan1 Okay, thanks.

Profile icon
EthanBlesch

@BrysonVan1 Which keywords would I use to save and access scores?

Profile icon
EthanBlesch

@BrysonVan1 how can I save and access scores, because this is just CONFUSING.