Ask coding questions

← Back to all posts
Make a highscore visible to all players of a game?
EthanBlesch (8)

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

Comments
hotnewtop
BrysonVan1 (11)

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

EthanBlesch (8)

@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

btfuss (177)

@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)

EthanBlesch (8)

@btfuss wuuuuuuuuuuuuuuuuuuuuuut

BrysonVan1 (11)

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

BrysonVan1 (11)

@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.

EthanBlesch (8)

@BrysonVan1 so what would this look like as pseudocode?

EthanBlesch (8)

@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?

EthanBlesch (8)

@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.

BrysonVan1 (11)

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

EthanBlesch (8)

@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.

BrysonVan1 (11)

@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)

EthanBlesch (8)

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

EthanBlesch (8)

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