Create "login" screen and save user data


#1

I’m looking for a way to make a sort of login screen. Doesn’t need to be complicated, just something that on the first time loading the game it asks for a name and when the user plays again says something like “Welcome back [insert name]”. I’d also like to implement a sort of daily or timed bonus thing, where the user can only claim the bonus once every few hours, and with every consecutive login/claim the bonus gets better. I was looking at what @will was saying in this post: Is it possible to make it to where the player can save and load his game progress?. It seems like a good approach, but I thought I’d get some extra opinions before settling on anything.


#2

You should implement it using HTML tags over the canvas of PlayCanvas, as PlayCanvas doesn’t have an input box to type text.
You can start from these examples:

https://developer.playcanvas.com/en/tutorials/?tags=html


#3

you could ask the devs that made tankx.io , they implemented FB and twitter api login to save user data

welp that game is having issues right now I think


#4

tanx.io is the correct link :wink:


#5

Neither of them work? :face_with_raised_eyebrow:
I can’t even get to it from the explore section on the homepage.
https://playcanvas.com/explore/featured


#6

tanx.io works fine for me. Do you have a browser extension blocking it? Try the https version https://tanx.io/


#7

I just get this:


I disabled adblock, and my firewall shouldn’t be blocking it.


#8

How bizarre. Not sure what is up with that then :thinking:


#9

Yeah, I think the US server is down. The EU one is OK, I believe. When we get some time, we’ll bring it back up. Sorry for the inconvenience.


#10

Ah, that would make sense.


#11

will there be a GitHub repository on the PlayCanvas organization for Tanx.io


#12

No, we don’t have any plans to open source the game.


#13

o ok, it would be intresting if it was open source


#14

Is this still down? I still can’t connect to it so I’m assuming it is.


#15

wow its still down


#16

Yup, still nothing. Anyone got any other examples for making some sort of login/user data storage?


#17

If you only wanna do simple things like keeping track of a Username or points you could simply use Cookies for that.

Cookies can be easily “hacked” tho, but if you don’t mind, it would be the easiest route.

https://www.w3schools.com/js/js_cookies.asp


#18

Simple tings, ye, but I would rather avoid cookies. I don’t want any sort of complicated login system, like a facebook/twitter thing, or anything that would need an email at the moment. The best approach I’ve seen is probably how @will has it in accelerally using local storage, but I haven’t been able to get it working in my project.


#19

Oh I didn’t know about localstorage lol.

What problems have you been having? The code to use localstorage seems pretty simple! :slight_smile:


#20

This is how he calls the local storage:

if (localStorage) {
        var storedBestDistance = localStorage.getItem('accelerally-best-distance');
        if (storedBestDistance !== null) {
        this.bestDistance = parseFloat(storedBestDistance);
    }
}

The part I’m having trouble with is more so understanding it. The local storage item 'accelerally-best-distance' is he creating here as well as looking for it, or does he make it somewhere else?