TeaseStorage with complex variables
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
TeaseStorage with complex variables
Hi,
I'm making a tease and got to the point where I want to store some variables.
I have a player variable and it contains a lot of information (in variables of course).
The problem is, that when I try to save it, it doesn't seem to work. I don't want to do it for each member, because then I will end up with 100+ variables to be saved individually and I did not even mention the scenario when I want to modify these vars later and having to edit it in the saving function.
My question is: what am I doing wrong?
Code is like this:
var player={
stuff:"",
otherStuff:{member:0,member:1,},
currentSaveSlot:"Slot1",
}
function saveGame()
{
teaseStorage.setItem(player.currentSaveSlot+"Player",player);
}
function loadGame(slot)
{
player=teaseStorage.getItem(slot+"Player");
}
Any help is appreciated.
Ph.
I'm making a tease and got to the point where I want to store some variables.
I have a player variable and it contains a lot of information (in variables of course).
The problem is, that when I try to save it, it doesn't seem to work. I don't want to do it for each member, because then I will end up with 100+ variables to be saved individually and I did not even mention the scenario when I want to modify these vars later and having to edit it in the saving function.
My question is: what am I doing wrong?
Code is like this:
var player={
stuff:"",
otherStuff:{member:0,member:1,},
currentSaveSlot:"Slot1",
}
function saveGame()
{
teaseStorage.setItem(player.currentSaveSlot+"Player",player);
}
function loadGame(slot)
{
player=teaseStorage.getItem(slot+"Player");
}
Any help is appreciated.
Ph.
-
kerkersklave
- Explorer At Heart

- Posts: 709
- Joined: Sun Jul 06, 2014 2:11 pm
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Slave
Re: TeaseStorage with complex variables
I seem do be able to store complex objects just fine.
Did you enable the storage module in the settings?
Did you enable the storage module in the settings?
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
Of course I enabled it, thanks for the reply.
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
Could you paste here the code snippet for me to inspect?kerkersklave wrote: Mon Dec 23, 2019 7:12 pm I seem do be able to store complex objects just fine.
Did you enable the storage module in the settings?
-
undeniable_denial
- Explorer At Heart

- Posts: 109
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: TeaseStorage with complex variables
My advice would be: Start with a minimal working example (Just recreate the one from the tutorial) and flesh it out from there. Make it more complex step by step. That way you will quickly identify the problem.
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
I'm trying just that, but still could not figure out why it didn't save what it needed to.undeniable_denial wrote: Mon Dec 23, 2019 8:12 pm My advice would be: Start with a minimal working example (Just recreate the one from the tutorial) and flesh it out from there. Make it more complex step by step. That way you will quickly identify the problem.
-
kerkersklave
- Explorer At Heart

- Posts: 709
- Joined: Sun Jul 06, 2014 2:11 pm
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Slave
Re: TeaseStorage with complex variables
I just did the following:Philocalist wrote: Mon Dec 23, 2019 7:21 pm Could you paste here the code snippet for me to inspect?
Code: Select all
teaseStorage.setItem("asd", [{asd: "foo"},2,3]);
teaseStorage.getItem("asd")[0].asd;
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
So the teaseStorage can store Arrays, and objects in arrays, but not just objects.kerkersklave wrote: Mon Dec 23, 2019 8:16 pmI just did the following:Philocalist wrote: Mon Dec 23, 2019 7:21 pm Could you paste here the code snippet for me to inspect?Code: Select all
teaseStorage.setItem("asd", [{asd: "foo"},2,3]); teaseStorage.getItem("asd")[0].asd;
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
Code: Select all
var DataHolder=
[
slot1InUse=false,
slot2InUse=false,
slot3InUse=false,
Slot1Player=undefined,
Slot1Coordinates=undefined,
Slot2Player=undefined,
Slot2Coordinates=undefined,
Slot3Player=undefined,
Slot3Coordinates=undefined,
]
function saveGame()
{
switch(player.currentSaveSlot)
{
case "Slot1":
DataHolder[3]=player;
teaseStorage.setItem("DataHolder",DataHolder);
break;
}
}
function loadGame(slot)
{
DataHolder=teaseStorage.getItem("DataHolder")[0];
switch(slot)
{
case "Slot1":
player=DataHolder[3];
break;
}
}-
undeniable_denial
- Explorer At Heart

- Posts: 109
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: TeaseStorage with complex variables
Arrays are objects in JavaScript.
There are several things wrong with your code, such as the entire declaration of DataHolder
What you probably meant was something like this:
It seems to me that you are confused about arrays and objects.
Arrays are bit like lists: array1 = [value1, value2, value3];
Objects are bit like 2-column-tables: object1: {key1:value1, key2:value2, key3:value3};
It seems you were trying to create some kind of "map" that exists in other programming languages, but not in JS. Objects are usually used for this.
DataHolder[3] should be DataHolder.Slot1Player or DataHolder["Slot1Player"]
None of this is important right now, however, until you have determined if TeaseStorage is actually working for you. As I have mentioned earlier you should try to recreate the tutorial and check if it works.
If it does: Your code is wrong.
If it doesn't: Something else is wrong and the code doesn't matter.
There are several things wrong with your code, such as the entire declaration of DataHolder
What you probably meant was something like this:
Code: Select all
var DataHolder={
slot1InUse : false,
etc...,
Slot3Coordinates : undefined
};Arrays are bit like lists: array1 = [value1, value2, value3];
Objects are bit like 2-column-tables: object1: {key1:value1, key2:value2, key3:value3};
It seems you were trying to create some kind of "map" that exists in other programming languages, but not in JS. Objects are usually used for this.
DataHolder[3] should be DataHolder.Slot1Player or DataHolder["Slot1Player"]
None of this is important right now, however, until you have determined if TeaseStorage is actually working for you. As I have mentioned earlier you should try to recreate the tutorial and check if it works.
If it does: Your code is wrong.
If it doesn't: Something else is wrong and the code doesn't matter.
Last edited by undeniable_denial on Mon Dec 23, 2019 11:52 pm, edited 3 times in total.
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
Thanks for the help, I'll check.undeniable_denial wrote: Mon Dec 23, 2019 11:31 pm Arrays are objects in JavaScript.
There are several things wrong with your code, such as the entire declaration of DataHolder
What you probably meant was something like this:Furthermore I have absolutely no idea what you mean by DataHolder[3]Code: Select all
var DataHolder={ slot1InUse : false, etc..., Slot3Coordinates : undefined };
None of this is important right now, however, until you have determined if TeaseStorage is actually working for you. As I have mentioned earlier you should try to recreate the tutorial and check if it works.
If it does: Your code is wrong.
If it doesn't: Something else is wrong and the code doesn't matter.
by DataHolder[3] I meant the fourth instance, thinking of it as an array
the basic tutorial example works for me, I just can not put the player var inside, so I made this DataHolder as an ultimate storage unit to simplify things
-
undeniable_denial
- Explorer At Heart

- Posts: 109
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: TeaseStorage with complex variables
You caught me while I was editing. I eventually realized what you were trying to do. Please see my edited post.
-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
As you might have guessed JS is not my go-to language. The advice is wellcomed and noted, I have been using objects in the project, but I thought that the TeaseStorage only supported Arrays.undeniable_denial wrote: Mon Dec 23, 2019 11:51 pm You caught me while I was editing. I eventually realized what you were trying to do. Please see my edited post.
Still, I can not store this DataHolder variable in teaseStorage.
Any idea?
Code: Select all
var DataHolder=
{
slot1InUse:false,
slot2InUse:false,
slot3InUse:false,
Slot1Player:undefined,
Slot1Coordinates:undefined,
Slot2Player:undefined,
Slot2Coordinates:undefined,
Slot3Player:undefined,
Slot3Coordinates:undefined,
}
function saveGame()
{
switch(player.currentSaveSlot)
{
case "Slot1":
DataHolder.Slot1Player=player;
teaseStorage.setItem("DataHolder",DataHolder);
break;
}
}
function loadGame(slot)
{
DataHolder=teaseStorage.getItem("DataHolder");
switch(slot)
{
case "Slot1":
player=DataHolder.Slot1Player;
break;
}
}-
undeniable_denial
- Explorer At Heart

- Posts: 109
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: TeaseStorage with complex variables
I think you're trying to do too much at once. I still would recommend modifying the tutorial step-by-step.
Since you like to go all in, may I introduce you to this useful command:
How to see the console depends on your browser. Usually it can be accessed by pressing the F12-key. There will be numerous tabs. One of them is called "console".
This command is super helpful in debugging. For example insert it inside your switch so that you can tell if it even gets executed.
Here are 2 examples:
Since you like to go all in, may I introduce you to this useful command:
Code: Select all
console.log("Hello world!");This command is super helpful in debugging. For example insert it inside your switch so that you can tell if it even gets executed.
Here are 2 examples:
Code: Select all
function saveGame()
{
console.log("Save slot: "+player.currentSaveSlot);
switch(player.currentSaveSlot)
{
case "Slot1":
console.log("Hooray");
DataHolder.Slot1Player=player;
teaseStorage.setItem("DataHolder",DataHolder);
break;
}
}-
Philocalist
- Explorer

- Posts: 51
- Joined: Mon Dec 03, 2018 8:30 pm
- Gender: Male
- Sexual Orientation: Straight
Re: TeaseStorage with complex variables
helpful indeed, does this mean that teaseStorage has an input limit after all?:undeniable_denial wrote: Tue Dec 24, 2019 12:20 am I think you're trying to do too much at once. I still would recommend modifying the tutorial step-by-step.
Since you like to go all in, may I introduce you to this useful command:How to see the console depends on your browser. Usually it can be accessed by pressing the F12-key. There will be numerous tabs. One of them is called "console".Code: Select all
console.log("Hello world!");
This command is super helpful in debugging. For example insert it inside your switch so that you can tell if it even gets executed.
Here are 2 examples:
Code: Select all
function saveGame() { console.log("Save slot: "+player.currentSaveSlot); switch(player.currentSaveSlot) { case "Slot1": console.log("Hooray"); DataHolder.Slot1Player=player; teaseStorage.setItem("DataHolder",DataHolder); break; } }
https://postimg.cc/crXG0rW9
