Page 2 of 2
Re: TeaseStorage with complex variables
Posted: Tue Dec 24, 2019 1:16 am
by undeniable_denial
I guess so.
I haven't yet made use of TeaseStorage, so I have no experience. However, I would guess, that the data structure gets converted to a JSON-string and there might be a hard character limit.
You seem to be aiming for a point-and-click/maze adventure, no? I don't think that's too much too ask in terms of storage. I'm sure you'll find a way. Maybe as simple as using more than one storage-item.
Re: TeaseStorage with complex variables
Posted: Tue Dec 24, 2019 1:30 am
by Philocalist
undeniable_denial wrote: Tue Dec 24, 2019 1:16 am
I guess so.
I haven't yet made use of TeaseStorage, so I have no experience. However, I would guess, that the data structure gets converted to a JSON-string and there might be a hard character limit.
You seem to be aiming for a point-and-click/maze adventure, no? I don't think that's too much too ask in terms of storage. I'm sure you'll find a way. Maybe as simple as using more than one storage-item.
Kind of like a maze adventure, yes. Rather open map than maze. Actually I'm getting ok with the fact that I have to write a function to put everything I need in the storage. Thanks for the help, I’ll be back if that does not work out.

Re: TeaseStorage with complex variables
Posted: Wed Dec 25, 2019 8:11 am
by RemiHiyama
undeniable_denial wrote: Tue Dec 24, 2019 1:16 amHowever, I would guess, that the data structure gets converted to a JSON-string and there might be a hard character limit.
If I'm interpreting the javascript code I'm looking at correctly, the maximum size is 1kb, and it is stored as JSON. Which means you've got the JSON formatting and your variable names using up the space in addition to your actual data. Still plenty for a lot of purposes, but doing anything really complicated might require getting creative.
Re: TeaseStorage with complex variables
Posted: Wed Dec 25, 2019 9:48 pm
by Philocalist
So a quick update here, I'm trying with a function which packs the individual components separately to the teaseStorage. Any idea how can I put them back together? I was thinking about something which loops through the objects and fills the corresponding part, but I don't know if the for-in cycle would be a good fit here.
if you are wondering:
Code: Select all
function saveGame()
{
var elementIndex=0;
var element;
var anotherElement;
var anotherElementIndex=0;
for(element in player)
{
if(element=="items")
{
teaseStorage.setItem(player.currentSaveSlot+"IC",element.currentCapacity);
for(anotherElement in element)
{
console.log(anotherElement);
teaseStorage.setItem(player.currentSaveSlot+"I"+anotherElementIndex,anotherElement);
anotherElementIndex++;
}
anotherElementIndex=0;
for(anotherElement in element.temporaryInventory)
{
teaseStorage.setItem(player.currentSaveSlot+"IT"+anotherElementIndex,anotherElement);
anotherElementIndex++;
}
}
else
{
teaseStorage.setItem(player.currentSaveSlot+"P"+elementIndex,element);
}
console.log(element);
elementIndex++;
}
elementIndex=0;
anotherElementIndex=0;
for(element in coordinates)
{
for(anotherElement in element)
{
teaseStorage.setItem(player.currentSaveSlot+"C"+elementIndex+"C"+anotherElementIndex,anotherElement);
console.log(anotherElement);
anotherElementIndex++;
}
anotherElement++;
}
}
edit:
I might need to reimagine this function:
https://postimg.cc/Zv6YTjtB

Re: TeaseStorage with complex variables
Posted: Fri Dec 27, 2019 6:54 am
by RemiHiyama
Can't you just use setItem directly with complex objects like whatever's in "player"? Unless there's something really weird going on in there, letting JSON handle it is probably going to be easier and more space-efficient than having so many separate variables.
If running out of space is really a problem, I think you'd need to start looking at things that convert your data to compact string representations. Like turning
[1,2,3,4]
into
"1234".
Or mapping numbers to letters, so
[1,5,26,28]
could turn into
"aezB"
and that way you could handle numbers higher than 10 in a single character. It feels a bit like reinventing compression, but given the limits of the environment, that sort of trick might be what it would take.
Re: TeaseStorage with complex variables
Posted: Sat Dec 28, 2019 11:00 am
by Philocalist
RemiHiyama wrote: Fri Dec 27, 2019 6:54 am
Can't you just use setItem directly with complex objects like whatever's in "player"? Unless there's something really weird going on in there, letting JSON handle it is probably going to be easier and more space-efficient than having so many separate variables.
If running out of space is really a problem, I think you'd need to start looking at things that convert your data to compact string representations. Like turning
[1,2,3,4]
into
"1234".
Or mapping numbers to letters, so
[1,5,26,28]
could turn into
"aezB"
and that way you could handle numbers higher than 10 in a single character. It feels a bit like reinventing compression, but given the limits of the environment, that sort of trick might be what it would take.
If I could store the player as a whole there would be no discussion here.
What you suggested makes a lot of sense and probably will be part of the solution. I think I will postpone this saving aspect to a later phase, so the variables will be finalized.
Re: TeaseStorage with complex variables
Posted: Mon Jan 13, 2020 4:49 pm
by undeniable_denial
If the limit really is 1kB, i.e. 1000 characters, then I would also try to make the variables/property names as short as possible, since they take up space, too.
I mean, if your average variable name is 5 characters long, you can only store less than 1000/5=200 variables.
What I'm trying to say is:
Code: Select all
{"saveSlot1":{"theExactPositionInTheGameWorld":{"xCoordinate":"5","yCoordinate":"12"}}}
108 characters to store
vs
23 characters to store
Just saying.
Try
Code: Select all
console.log(JSON.stringify(player));
and see what it looks like. Maybe you can tell by eye what's taking so much space.
Re: TeaseStorage with complex variables
Posted: Sun Jun 07, 2020 9:33 am
by WankToy
Try this to save some chars/space.
Code: Select all
// ucs-2 string to base64 encoded ascii
function utoa(str) { return window.btoa(unescape(encodeURIComponent(str))); }
// base64 encoded ascii to ucs-2 string
function atou(str) { return decodeURIComponent(escape(window.atob(str))); }
// Usage:
utoa('✓ à la mode'); // 4pyTIMOgIGxhIG1vZGU=
atou('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode"
utoa('I \u2661 Unicode!'); // SSDimaEgVW5pY29kZSE=
atou('SSDimaEgVW5pY29kZSE='); // "I ♡ Unicode!"
console.log(utoa(JSON.stringify(player)));