Same Save/LoadState from different locations

Monkey Targets Forums/HTML5/Same Save/LoadState from different locations

Hezkore(Posted 2014) [#1]
If I run my HTML5 game from for example www.MyHompage.com and use SaveState, then run the very same game from something like www.OtherHomepage.com and use LoadSate, it'll return nothing since SaveState was called on a different homepage, even though the data is saved locally!

Is it possible to enter some sort of publish name or something for HTML5 applications so that the local data is saved in the same location?
Cause this is giving me lots of problems since my game uses search strings, so sometimes it might look like "game.html?level=foo" and other times "game.html?level=bar" and all the SaveState data is gone.


k.o.g.(Posted 2014) [#2]
You must fix the lines at 100 to 109 in modules/brl/native/gametarget.js

BBGame.prototype.SaveState=function( state ){
	localStorage.setItem( "monkeystate@... );	//key can't start with dot in Chrome!
	return 1;
}

BBGame.prototype.LoadState=function(){
	var state=localStorage.getItem( "monkeystate@... );
	if( state ) return state;
	return "";
}



Try this:
BBGame.prototype.SaveState=Function( state ){
	var url = window.location.href.match(/^[^\#\?]+/)[0];
	localStorage.setItem( "monkeystate@"+url,state );	//key can't start with dot in Chrome!
	return 1;
}

BBGame.prototype.LoadState=Function(){
	var url = window.location.href.match(/^[^\#\?]+/)[0];
	var state=localStorage.getItem( "monkeystate@"+url );
	if( state ) return state;
	return "";
}



Hezkore(Posted 2014) [#3]
Yeah I had a look at it, but I really don't like having to change Monkey itself to fix things. :/
Oh well, if it's the only way!


k.o.g.(Posted 2014) [#4]
you can create a new Javascript File (statefixed.js)
put this code in;
BBGame.prototype.SaveState = function(state) {
	var url = window.location.href.match(/^[^\#\?]+/)[0];
	localStorage.setItem("monkeystate@" + url, state); //key can't start with dot in Chrome!
	return 1;
}

BBGame.prototype.LoadState = function() {
	var url = window.location.href.match(/^[^\#\?]+/)[0];
	var state = localStorage.getItem("monkeystate@" + url);
	if (state) return state;
	return "";
}


and in your MonkeyFile insert
import mojo.app
#if TARGET="html5"
import "statefixed.js"
#end


The SaveState and LoadState function will be overwritten


Hezkore(Posted 2014) [#5]
You're my hero. <3
I'll use this "trick" on my texture repeat function.


Hezkore(Posted 2014) [#6]
Is there any similar way to expand Mojo and its functions/methods?
I'd like to add a TextureRepeat function to Mojo.Graphics.