Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
saving game to the database
#1
Im currently making a visual novel with database. Im using xamp.
players can register to play the game. my problem is how to connect the save game to the xamp database of the player.

Can someone help me. how to connect WSE save game to xamp database and making all my save game be stored in the databse rather than be save in the browser.

thanks you. Smile Heart Blush

btw, you can contact me thru gmail @ crynx.martinez@gmail.com
or facebook http://www.facebook.com/el.martinez.501
Reply
#2
Hi crynx.martinez!

I have just released a new version of the engine:
https://github.com/iiyo/WebStory-Engine/...ag/v2017.1

This release allows you to write your own data source. Take a look at the default data source (localStorage):
https://github.com/iiyo/WebStory-Engine/...Storage.js

Your data source must have the same interface, that is, it must supply the following methods:

Code:
.set(key, value)
.get(key)
.remove(key)

Unfortunately, the interface is synchronous. So what you have to do in your data source implementation is to send the data to your server via AJAX and not wait for a response.

You can tell the engine to use your own data source by adding it to the options in your index.html file:

Code:
               
               var game = new Game({
                   url: "story/game.xmugly",
                   host: typeof HOST === "undefined" ? false : HOST,
                   datasource: new MyCustomDataSource() // This is where you add your own data source
               });

Hope this helps!
Reply
#3
(01-15-2017, 09:36 AM)jfhs Wrote: Hi crynx.martinez!

I have just released a new version of the engine:
https://github.com/iiyo/WebStory-Engine/...ag/v2017.1

This release allows you to write your own data source. Take a look at the default data source (localStorage):
https://github.com/iiyo/WebStory-Engine/...Storage.js

Your data source must have the same interface, that is, it must supply the following methods:

Code:
.set(key, value)
.get(key)
.remove(key)

Unfortunately, the interface is synchronous. So what you have to do in your data source implementation is to send the data to your server via AJAX and not wait for a response.

You can tell the engine to use your own data source by adding it to the options in your index.html file:

Code:
               
               var game = new Game({
                   url: "story/game.xmugly",
                   host: typeof HOST === "undefined" ? false : HOST,
                   datasource: new MyCustomDataSource() // This is where you add your own data source
               });

Hope this helps!

Hello! I am fairly new to programming and I am also trying to save the game in a database. I read your reply to crynx.martinez over and over but I just couldn't understand Sad Where do I find my own data source? And what do the set, get, and remove methods do? What is the key in their parameters? Do I have to use AJAX? Im sorry I have a lot of questions I just really dont know anything :Sad tried searching but dumb me couldn't find/understand anything.
Reply
#4
Hi adriitakumi!

You cannot find your datasource, you have to implement it yourself. And yes, your datasource has to use AJAX to send the data to the server. The key in the set, get an remove methods can be any string, but must be unique. Since you can save more than one set of data, you need the key to identify which data set you mean. So you would write an object with a set, a get and a remove method and you can use whatever is given to your methods as a key to find the appropriate data in your database.
Reply
#5
(02-19-2017, 09:48 PM)jfhs Wrote: Hi adriitakumi!

You cannot find your datasource, you have to implement it yourself. And yes, your datasource has to use AJAX to send the data to the server. The key in the set, get an remove methods can be any string, but must be unique. Since you can save more than one set of data, you need the key to identify which data set you mean. So you would write an object with a set, a get and a remove method and you can use whatever is given to your methods as a key to find the appropriate data in your database.

I have a doubt, I create a database called 'mybase' with 1 table, with 'key' and 'value', type int in the database in (mysql), in the game code I put:

Var game = new Game ({
                    Url: "story / game.xmugly",
                    Host: typeof HOST === "undefined"? False: HOST,
                    Datasource: new MyCustomDataSource () // <-
                });


My question is: Should I create the get and set methods, is there any easy way to do this?


  I am a beginner in programming.

I want the users to register and use their name as a game character.
Reply
#6
Hi sweetkaylee,

unfortunately no, there's no easy way. You have to write the datasource yourself, that means all the methods mentioned above:

Code:
.set(key, value)
.get(key)
.remove(key)

Maybe some of the other people in this thread already have a working version and are willing to share their datasource code?

But even if they do, I hope you are aware that you also need some code on the server to interact with your database and provide the means to login.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)