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.
TeaseStorage with complex variables
-
- Explorer
- Posts: 96
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
-
- Explorer
- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
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.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.
-
- Explorer At Heart
- Posts: 203
- Joined: Thu Feb 28, 2019 3:30 pm
- I am a: Switch
Re: TeaseStorage with complex variables
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.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.
Auto: Replaces selected instances of the word "not" with the word "definitely".
-
- Explorer
- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
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:
edit:
I might need to reimagine this function:
https://postimg.cc/Zv6YTjtB
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++;
}
}
I might need to reimagine this function:
https://postimg.cc/Zv6YTjtB
-
- Explorer At Heart
- Posts: 203
- Joined: Thu Feb 28, 2019 3:30 pm
- I am a: Switch
Re: TeaseStorage with complex variables
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 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".
-
- Explorer
- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
If I could store the player as a whole there would be no discussion here.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.
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.
-
- Explorer
- Posts: 96
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: TeaseStorage with complex variables
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:
108 characters to store
vs
23 characters to store
Just saying.
Try and see what it looks like. Maybe you can tell by eye what's taking so much space.
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"}}}
vs
Code: Select all
{"save1":{"pos":"E12"}}
Just saying.
Try
Code: Select all
console.log(JSON.stringify(player));
- WankToy
- 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
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
Who is online
Users browsing this forum: No registered users and 11 guests