MeshMemory general information
Mesh Memory can be used to read and write values from the internet to allow data sharing between two different users of the same web page. Consider you have written a game in HTML and Javascript and wish to provide a simple list of high scores. The classic approach is to host your own server and have server side programs to maintain this information. With Mesh memory you store a piece of information into the mesh, and can retrieve it anywhere.
Quick Example
- Open the web page /MeshMemoryDemo.htm in a web browser
- Change the values and press write to change the stored value.
- Optionally, open the same web page from another machine at the same time and observe how the value can be passed between the two browsers
- Optionally, save the source of the demo HTML file to your local disk, and then open it from your local copy, rather than the internet. The value is still able to be passed to and from the internet. Technically, this is using CORS support to allow resource sharing
Adding Mesh Memory to your own applications
1. Include the script to implement the Mesh Memory API calls. Add this line to your HTML file
<script src="http://www.fieldpine.com/MeshMemory.js"></script>
2. Add support for where you want to read the value into your code.
... FieldpineMeshMemory_Read("/MyExampleGame/HighScores", HighScoresReadCompleted); ...
3. Add the function that is called when the value has been read from the internet
function HighScoresReadCompleted(theVar) { // theVar is the last value written to the internet // eg write it to the screen document.getElementById("highscore").innerHTML = theVar.HighScore; }
4. Add code to update the high score
function UpdateHighScore(nHigh) { if (nHigh > CurrentHighScore) { var o = new Object; o.HighScore = Number(nHigh); FieldpineMeshMemory_Write("/MyExampleGame/HighScores", o); } }