Blog 26

Today we talked about the multiplayer mode of our games again. Todd talked about the JSon coding that he had been working on, and how we will need to implement it into our game.

Todd will give us JsnDrop code (which we will place in jsnDrop class) and we will drag this script onto a GUI component.

Making use of Jsn system is when I ask person to move.

The code we put into the MoveInDirection() function of Player, which in my application is Move() in the Person class and this below code allows our player class to interact with the json server:

string anID = MakePlayerID();



To split a the jsn command handed to the server we worked through the different methods of splitting a string into a list of json things and then we can jsonise these things.

I suggested the use of the arguments.split function which was recommended as an answer to a question in this stackoverflow webpage


The code we decided on to use to split the string from the server as a result of the JsnGet command was:

private List<string> getJSNStrings(string pServer) //Get my Jsn strings. i.e. break information from server and put it in a list
List<string> result = new List<string>();    //create a string array
var parts = Regex.Split(pServer, “},{“); //Use a regular expression to split the string from json where there is a },{ in the string
foreach(string part in parts)
string newString = part.Replace(“{“,””); //Split the curly brackets off the split values
newString = newString.Replace(“}”,””);
newString = “{“+newString+”}”;
result.Add(newString); //Produce a list of the json records we are after.
return result;

So using the supplied code what do we have to do for milestone 3?

We need to display what scene each player is in at a particular point in time.


Player 1 Scene 5

Player 2 scene 10

One way to do this is  having another screen (like inventory screen) that calls the server to get the player information to display it. So every time the player moves scene we need to call the function that inputs the player and scene data to the server by JsnPut command.

Every time you move you need to get the player information of what scene each player is at in a specific point in time.





Blog 25

Today we walked about making our games multiplayer, using JsnDrop data service, we will be using this so we can store data online.

JsonDrop is accessible through writing  into our web browser.

Json queries are:

  1. JsnReg- You have to register to get a number to be able to put data into the server. To register I write gamename, tablename, password. e.g. “ExploreSantorini”, “tblLocation”, “Pa21” and this returns a ID number for you to use in every JsnPut and JsnGet command. this creates a storage with an ID.
  2. JsnPut- This must have an your register number, an id, and a pattern to input data in the server. The first record stored using JsnPut includes the names and values and it forms the schema of the database on the server. You don’t write create table as the first JsnPut creates the schema of the table automatically.  e.g. 1, “id”:2, {“id”:2, “Score”:100} Replace any field that’s mentioned.
  3. JsnGet- Must get the number of the table you want to retrieve data of, If you just want one record with id=2 then you would write in 1, {“id”: 2}  (this gets whole record with id:2) or you could get everyone by the same password by writing in 1, {“password”:Password1}
  4. JsnKill- This lines up with JsnReg. It kills the storage, basically the equivalent of the DELETE DATABASE query.
  5. JsnDel- Must give the ID number, then give pattern. To delete ID 2 I would write in 1, “ID:2”

All these patterns are to be written into the web browsers URL line.

My game name is “ExploreSantorini” (which I will have to write into the URL address line) and I decide the name of the tables and a password.

Examples of using the jSon queries are:

  2. To kill the table write in,tbllocation,Kelly1

iage 2.PNG


We need a table with player name and location to keep track of players in multiplayer mode of our game. So I will write in the following Json commands,”PlayerID”:1, {“PlayerID”:1,”LocationID”:10}

as I can see with the below response I have created made the schema of the tblLocation table.

image 3.PNG

Now to get the data out of JSon is jsnGet.,”PlayerID”:1, {“PlayerID”:1,”LocationID”:10}

To get all data out of a table write:

To delete a record from the table write:,40,”PlayerID”:1


We are just using jSon for multi user mode for the players name, score, and location. We need a class that sends this data to the server and gets the response, this is pre-made Unity object.

The instructions to set up jSon is:

1.The first step which is register

2. Get PlayerID from the server for use in the local machine for identifying the player



Project work:

I want to work on getting my accelerometer script working.

I have installed Unity Remote 5 application on my Android tablet so I can use my phone and the laptop to test the accelerometer to move between scenes on my phone. Now that we have been taught about Json I want to start working on getting this working.

Blog 24

Today we talked about using an accelerometer which detects the direction that the device the game is being on is moving in, and so the scene on the game can be changed.

We need to implement a new script named AccelerometerInput

using UnityEngine;
using System.Collections;

public class AccelerometerInput : MonoBehaviour 
    void Update () 
        transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);

I tried to get this script to run however I had issues with the timer, as this fake accelerometer is not a requirement of the assignment I am not going to spend time troubleshooting to get it working due to time constraints from all my other assignments.




Blog 23

Today we talked about Json. In our games we will need to make a transfer object so in addition to having Item object, and ItemDTO table we also need a Item network transfer object (i.e. make a new script named ItemNTO) used for sending information to the server using json.

We will transfer the player and the scene they are in. json is an encapsulation of objects that get sent to the server.

json requires a public variables. We have to make a converter to take a particular class and serialize it before we can transmit it. Thus we have to convert the object to a string to transmit it, and so we require the ToString function in the class.

So to clarify we make a NTO as well as DTO, and so we will have Item class, ItemDTO, and ItemNTO.

So today Todd introduced us to json for the first time and it looks to be an interesting concept to allow our C# local games to connect to the server.


Blog 21

Today I went through trying to work out why I was getting ‘SQLLite Constraint’ error of which I was getting 3 instances on one line which was in Camera rot script line 13 which is the call to the GameModel.makeScenes(); function.

I spent 7 hours trying to troubleshoot why I was getting these errors. I asked Todd and I got the advice to try installing Unity on my personal laptop and then try to see if I get the same errors this was to check if the error was unique to my computer. So I went through and installed Unity on my machine however I still got the same errors.

Another suggestion was to try copying across the SQLLite folders (streaming assets and plugins folders) from Todd’s code project on Moodle across to my project’s asset directory and to see because the error is a SQLlite constraint error if this replacement of the SQLLite directories would solve the issue. However again this did not work.

So I thought of going back to my milestone one work and adding the milestone two work onto it, I tried this by going back to my final milestone one handin, making a new version and then copying across the streaming asset and plugin folders into the asset folder, as well as copying across the dataservice. daatserviceutilities and sqllite scripts into my script folder and altering around my gamemodel script. Then I went through modifying the game model script so it called the data service script to make the scenes, and defined the scenes with IDs so they could be inserted into the scenes table.

Then I tested this new milestone two project and amazingly it worked!! I was very happy to see this and so later on I went to a meeting with Todd and managed to get the navigation between the scenes working with text input.

Todd said he thought the reason why my old milestone two project would’t work for no apparent reason was because it corrupted and unfortunately there is always one person in each class who gets their project corrupted.

Over the next few daays and the weekend I worked through the creation, loading and saving of the tables for each of my three domain classes: Item, disaster, and location.

I have made domain classes such as Item (which defines the AllItems list variable to store the item objects in the game from the table) as well as ItemDTO to store the item instances in the database. Thus I can access the item instances in the domain class or by cycling through the ItemDTO table retrieving the records.

I finally completed much of the coding on Wednesday and all I have to now is comment, and indent my code and then complete the other two diagrams: CRC cards and interaction diagram.






Blog 22

Today we talked about MS3. There are 2 parts:

  1. Having logged in global variable on game object stating your logged in-Session management
  2. Communicate with web server from our game app- This is more complex
  3. Get sensor information (e.g. grab picture from your camera and store it, or use movement on our device)- this is simpler

For part 1 Jason is used as wrapper for information sent over web. Wrap information in Jason using HTTP POST and send this to the web server.

Thus this milestone is implementing multiplayer mode of the game this is by having a request and post whenever the current player moves scene which says to web server “playerid=1 is in sceneid=2 who else is in this scene”. The table in the web server will have the following attributes GameID, SceneID, and PlayerID.

SceneID’s must be unique for your game.

NOTE: You don’t need to have map image screen working you could just display text list of all scenes and the players in them, which is accessed when the user types in “where is everyone”

Milestone 3 documentation-Resubmit every documentation , and add additional information about how you did what you’re doing, how you went about it, any problems and how you solved it



Blog 20

Today we continued to talk about the saving and loading of scenes, continuing on from last lesson. However when I took Todds code and applied it to my Explore Santorini game I had several issues which were:

  • The game wouldn’t start on the start_Scene instead it would start on TravelDestination.North.West scene which is not what I want
  • When entering a text command the text displayed didn’t change meaning you cannot change scene. The only textual command that worked successfully is “exit game” which takes the user back to the game menu interface.
  • Both the save and load buttons would not work

I went and sat next to David to see how he was getting on, he was getting some of the same problems as me, and he had a look at my code to update his with the latest code from Todd which I had already implemented.

I asked for help from Todd several times, the last time being at the end of class when he kindly helped me for a good hour.What we did was create a Scene DTO and Scene table in the database and then copy, paste and implement the save and load methods from the Data Services script. At one point we had 56 errors which was a bit alarming!! However we got it down to 2 errors now.

Effectively what I have to do next (same as David as he was having the same issue) is make a Player DTO and then copy, paste and implement the save and load of the player (this is being implemented so when the game goes to multiplayer in the future the players can be loaded in the game) and this should hopefully allow the game to start on the first scene, change scenes, and save and load correctly when the “save” and “Load” buttons are selected.

Again I will need to go through and comment the code Todd helped me with so I can understand how it works and implement the same concept for the Player.


Blog 19

Today we covered what is required for the milestone two handin of the SDV601 project. We need to:

  • Have game domain classes implemented. What bare game domain classes? These are classes specific to your game so in my case my game is called Explore Santorini it is a travel map-based game where the player moves around the island of Santorini visiting attractions (each of which costs 10 euros to visit and they must spend a further 5 euros to buy a souvenir in the attraction to prove they have visited it; the souvenir is added to their inventory) throughout the game a disaster may befall the player lowering their health and money. So the classes that can be identified as game domain classes for my game are: disaster, attraction, map, inventory.
  • SQLLite database storing the game data. Data Transfer Objects of each of the classes are used to store the classes data in this persistent storage medium.

We also need to ensure our code is indented, which is what I ensured I had done for the last milestone and that it is well commented without spelling mistakes. Again in the last milestone I made sure my game was well commented although I have to make sure the comments are on the same line of code they refer to as I made a mistake with the previous milestone.

As for the documentation we have to complete:

  • CRC cards
  • Class diagram
  • State diagram (this is optional)
  • Interaction diagram

I look forward to making these diagrams as we have recently made them in SYD601 so they should be relatively straight forward and it will be good to take knowledge from one paper and apply it to another.

As far as todays lecture on code went Todd talked about the saving and loading of scenes. A summary of what he covered is:

When the game starts we have to make scenes if we have a DB we load scenes from DB. If we don’t have scenes we  save scenes to the DB.

The system is making things as it needs it, so if it needs a table but it doesn’t exist then it  will create a table.

With Todds new code which he made available to us on Moodle:

  1. Click load button
  2. Goes to GameModel
  3. Goes to LoadScene() in DataServices.cs

I will now go through it and comment Todds code it as I find that by far the best way for me to understand code.


Blog 18

Today we hacked!!

  • Saving and loading ‘the scenes’ in SQLLite from the data structure on Todd’s system
  • Milestone 2

In Milestone 2: Due on the 19th of October

  • Add a login screen, connect to server for login
  • Implement game domain classes (we have interfaces (view), viewmodel (this is the control handling between the view and the model), model contains data this maps quite closely to our game domain classes which are specific to our game).

Examples of game domain classes are health, inventory. They are things your game specifically store or does. Each type of item would have its own class. e.g. Greek vase item, meal item. You can also have a manager for each of the domain classes.

  • Have data stored in the local storage SQLLite. So save and load scenes to SQLLite, and also save information about each of the game domain classes.
  • Use version control manager by uploading game onto GitHub.

Documentation (go through more of the ATM documentation) we need to make the following diagrams:

  • Interaction diagram
  • CRC cards
  • Sequence diagrams
  • State chart (optional) States of the game would be logged in and logged out. Executing a command is a state diagram we can make.

I am happy about making these diagrams because we have researched them in SYD601.

In today’s lecture we looked at how data structure of scenes will map to scenes. This is how we implement IDs to refer to scenes rather than using north.north etc. instead numerical IDs are used.

Every link (future scene you want to go to) that does not exist has a value of null in the database.

The Scene table in the database will have the attributes: ID, name, story

And we will also have a SceneToScene table which will be used to help us navigate between scenes. The SceneToScene table will have the attributes: FromID, ToID, Label (e.g. east depending on where the FromID and ToID is)

FromID    ToID    Label

S1                 S2       East

Todd’s scene mapping is flexible in making a arbitrary network, it will work with any type of map system.

The Data transfer objects are being used as our SQL schema at the moment.

Todd talked us through the way he has implemented save scenes and using the list in the Scene class named AllScenes which allows us to save all scenes in a list and then save each scene in the list in SaveScene method in DataServices script.


















Blog 17

Class notes:

Todd demonstrated more SQLLite. We looked at the MakeScenes() method and how this will work with the SQLLite database.

The database we need to use will have the following tables:

  • Game-Contains information about a game
  • Players-For each game we have player
  • Scene- Game scenes which the user navigates through by entering text input
  • Inventory
  • NPC
  • SceneItems- Items in a specific scene
  • ScenePlayer-A join table of the players in a specific scene
  • SceneNPC- A join table of the NPC in a specific scene

So our database will have 8 tables. The data in each table is:

Game(GameID (INT Autoincrement), Name, CurrentPlayer))

Scene(SceneId, GameID, Name, Story)

Player( PlayerID, GameID, Name, NPLStatus(enumerator type), PWD, Em)

PlayerStatus(PlayerID, AttributeName, Value)

Item (ItemID (Autoincrement), SceneID, InventoryID, Name, Power)

ScenePlayer (SceneID, PlayerID)

SceneNPC(SceneID, NPCID)

Inventory(InventoryID, PlayerID, IVPCID)

SceneToScene(FromSceneID, ToSceneID)

The entity relationship diagram created was:



To implement the SQLLite to our project. We copy the plugin and scripts folders across to our project from the SQLLite examples folder.

SQLLite code libraries don’t need you to explicitly load things you give it the template and it will load it.

Todd gave us a modified GameModel script; it was the same as our current GameModel script except for two lines of code. One was to use Dataservice and the other was to make a DB.

DataService script (from the scripts folder of example directory of SQL Lite) makes or finds a database.

All we have to do is connect to that connection and create DB.

If I want to do a data definition all I need to do is write a SQLLite version of query in the Data Services script.

So implement the database with our game is make a Data Service and run our queries against the Data Service. Rename this script GameService not DataService. Data Service sits behind model and does data work for us.

Write ‘using SQLite4Unity3D;’ at the top of all game domain classes.

We need to implement a Data Transfer Object (DTO) to make a database table for a game class. e.g. For my exisiting Scene class I need to make a Scene table so I will make a new class named “SceneDTO” and this class will have each column of the table with a Get and Set

So to create a table Scene with columns SceneID, GameID, and Surname we write the following code in the SceneDTO.

[primary key]

public string SceneID{Get;Set;}

public int GameID {Get;Set;}

public string Surname {Get;Set;}

String formatting simply indicates the position where data in a string will be placed in the Scene table when it is inserted. 

return string.Format (“[Scene: SceneID={0}, GameID={1},  Surname={2}, Age={3}]”, SceneID, GameID, Surname);

When make start scene make a new scene. When we make another scene TravelDirection we need a scene to scene record.

So when we make a start scene in the GameModel script we write in

Reproduce everything we do both in the game class and in the DTO.We are matching our internal (scenes made from Scene class) to external classes (scenes made in SceneDTO which is the external SQLLite database).

Start_scene=new Scene();

StartDTO=new SceneDTO();