TeaseStorage with complex variables

Post all technical issues and questions here. We'll gladly help you wherever we can.
undeniable_denial
Explorer
Explorer
Posts: 96
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: TeaseStorage with complex variables

Post 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.
Philocalist
Explorer
Explorer
Posts: 51
Joined: Mon Dec 03, 2018 8:30 pm
Gender: Male
Sexual Orientation: Straight

Re: TeaseStorage with complex variables

Post 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. ;-)
RemiHiyama
Explorer At Heart
Explorer At Heart
Posts: 203
Joined: Thu Feb 28, 2019 3:30 pm
I am a: Switch

Re: TeaseStorage with complex variables

Post 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.
Auto: Replaces selected instances of the word "not" with the word "definitely".
Philocalist
Explorer
Explorer
Posts: 51
Joined: Mon Dec 03, 2018 8:30 pm
Gender: Male
Sexual Orientation: Straight

Re: TeaseStorage with complex variables

Post 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
Image
RemiHiyama
Explorer At Heart
Explorer At Heart
Posts: 203
Joined: Thu Feb 28, 2019 3:30 pm
I am a: Switch

Re: TeaseStorage with complex variables

Post 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.
Auto: Replaces selected instances of the word "not" with the word "definitely".
Philocalist
Explorer
Explorer
Posts: 51
Joined: Mon Dec 03, 2018 8:30 pm
Gender: Male
Sexual Orientation: Straight

Re: TeaseStorage with complex variables

Post 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.
undeniable_denial
Explorer
Explorer
Posts: 96
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: TeaseStorage with complex variables

Post 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

Code: Select all

{"save1":{"pos":"E12"}}
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.
User avatar
WankToy
Explorer
Explorer
Posts: 13
Joined: Wed Dec 24, 2008 1:52 am
Gender: Male
Sexual Orientation: Straight
I am a: Submissive
Location: Germany
Contact:

Re: TeaseStorage with complex variables

Post 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)));
Goddess Lisa:
Spoiler: show
ImageImageImageImage
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests