How do I read global variables from database?

0 favourites
From the Asset Store
Globals 2.0
$3.60 USD
10% off
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi guys, I’m wondering is it possible to read my global variables from a database? For example, by setting my global variable to “10”. No matter who is playing my game the global variable is set to “10”. I want to make it so after each time a player plays my game, the global variable is deducted by 1. So from 10, it goes to 9,8,7.... until 0, and I’ll have a screen where if Global variable == 0, no one can play anymore. So the way I thought of is by creating a database table, and storing my variable as “10” in the table, then after each play I will subtract 1, and update the data to the table, so when the next player plays it reads the updated data which is now 9. Or is there any other simpler way of doing this?

  • Use Local storage plugin

    Then "at the start of the layout"-->access the saved data

    if the accessed data is bigger than 0-->subtract 1 from it and save it back and continue the game

    else-->do not play the game

  • Use Local storage plugin

    Then "at the start of the layout"-->access the saved data

    if the accessed data is bigger than 0-->subtract 1 from it and save it back and continue the game

    else-->do not play the game

    I am attempting to make it so, once the variable is changed, when a different user plays the game it picks off from the new data, so I don't think local storage would work, let me know if I'm wrong but from my understanding, local storage only works on the same user's PC, and if another user is accessing the game the variable resets.

  • Then in that case you will have to explain you whole situation

    I think that your task will require networking (read and write data from online servers).

  • I understood what you want. Here concepts of networking will come and unfortunately i have no knowledge regarding this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Using post php can do the job.

    I'm still wondering why you want to stop users playing your game. 🤔

  • Using post php can do the job.

    I'm still wondering why you want to stop users playing your game. 🤔

    It’s because I’m distributing prizes to them, and I only have 10 prizes, so the first 10 players to meet the criteria will receive the prizes, and once the global variable hits 0, no one gets to play as I won’t have anything else to distribute out.

  • Using post php can do the job.

    I'm still wondering why you want to stop users playing your game. 🤔

    And may I ask why post PHP and not get? Should I not be getting the data from my database tables using GET request?

  • Good morning,

    As i remember you need only read and post.

    Please give me some hours to get home , i remember i have a C2 project at my pc that will help you.

  • Good morning,

    As i remember you need only read and post.

    Please give me some hours to get home , i remember i have a C2 project at my pc that will help you.

    Good morning, that'll be amazing thanks you!

  • Hello,

    Unfortunately it will confuse you if i send you the project so,

    here is an example.

    First of all you need to create a page that accept php (000Webhost)

    You need to add a txt file at the root of your page and just write the number 10.

    Create another file and name it whatever you want xxxxx.php and insert this inside

    After that here are some events

  • Its a little confuse because the names are not match but, On start of layout request the txt file it has the number 10 inside.

    As you can see at the first picture $file = "your txt file name that include the number 10"

    At the 3rd picture you send the data to the php file, change the name to fit your php file.

    Sorry for the mess....

  • Its a little confuse because the names are not match but, On start of layout request the txt file it has the number 10 inside.

    As you can see at the first picture $file = "your txt file name that include the number 10"

    At the 3rd picture you send the data to the php file, change the name to fit your php file.

    Sorry for the mess....

    Thanks for guiding me, I will try to see how I can work my ways around your code!

  • What's stopping one player to run the game 10 times, or open it in 10 browser tabs, and collect all prizes?

  • What's stopping one player to run the game 10 times, or open it in 10 browser tabs, and collect all prizes?

    A local storage can restrict the player to run this twice.

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