Login to game before start

0 favourites
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Anyone tries create a login system to game?

  • I have a very basic but workable one built using Ajax, php and MySQL but not the time to make a tutorial as of yet.

  • droptank21 thanks for sharing your hard work, its displayable on cocoon too?

  • I don't really know. I suppose so long as the device has web connection it should. I haven't really looked too much into CocoonJS.

  • thank you drop +1 for this :)

  • Don't forget that you will need to manually change the url's in the Ajax Post and Ajax Get events to match your localhost or webserver structure.

  • droptank21, Thanks for the tuts. But the getstats.php is missing on file.

  • thanks ......

  • It wasn't really necessary for the login function. However, I guess since you want a player to login you will need an idea of how to easily show them their own info.

    Here is the link to the getstats.php example.

  • And, of course, showing them their stats is all well and good. But there also needs to be an easy way to update a stat.

    Here is the php code for that as well...Here

    Then ensure it updates the stats in the game to show the new stat score.

    For example:

    Mouse -> on right button clicks on object 1 -> Ajax -> Post to : "http://localhost/wwxmmo/addexp.php?username="& UsernameTxt.Text & "&password=" & PasswordTxt.Text (tag "addexp")

    Ajax->On "addexp" completed -> Ajax ->Request: "http://localhost/wwxmmo/getstats.php?username="& user

    Ajax-> On "getstats" completed -> [Text]stat1 -> Set text to Ajax.Lastdata

    Simple as that. The user clicks on an object, our game Posts a command to php. Php updates the database. When the ajax command finishes a request is sent to retrieve the updated stat from the database, we assign that stat to a text object and the new stat is then displayed in the game.

  • droptank21

    Good day, thank you for the idea, its really helpful.

    I have a question. How to filter the user when they login?

    Like for example on your database there is user level which is "admin and user".

    When user login it will redirect to user page. And when admin login it will redirect to admin page.

  • You would create a new column in sql for level. Then much as the stats query you would query the user's level and assign the result to a global variable. Then simply assign an event that will check the user's level and set the system to go to one layout for a user and another seperate layout for admin.

    Tinker around with the stats php code and you'll get the hang of it.

  • droptank21

    Hi droptank21.

    I have tried to get it to work but i am unsuccesfull.

    I understand your capx and php codes are correct, and that my knowledge is simply missing on how to integrate this onto the server.

    I have tried:

    Creating a database. (succesfull)

    Adding the database.sql to the phpmyadmin "sql" section (succesfull)

    Modding the php files with my database login data. (succesfull)

    Uploading the php files to my server. (public_html/wwxmmo)

    Uploading the capx to my server. (public_html/Login)

    And the result is that i get a register failure and a login failure.

    Do u have any idea what i am doing wrong?

    Kind regards.

    Savvy001

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Did you change the ajax request url's in the C2 capx to match the url's of the php pages on your web server?

    Example:

    "http://localhost/wwxmmo/login.php?username="& UsernameTxt2.Text & "&password=" & PasswordTxt2.Text

    To

    "http://savvy001.com/wwxmmo/login.php?username="& UsernameTxt2.Text & "&password=" & PasswordTxt2.Text

    Be sure to check the syntax of your ajax code as well. Specifically ensuring there are spaces after the ampersands (&) denoting the data.

    (&_UsernameTxt2.Text &_)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)