Page 1 of 1

Need help with saves!

Posted: Wed Aug 10, 2022 6:07 pm
by ritewriter
Hi all,

Big favor to ask.

I am trying to add saves to my tease and failing miserably. If any of you have the time and expertise, would you be so kind as to look at my effort and tell me how to fix whatever is going wrong.

My save strategy is:

CHECKPOINTS

- Create a dozen or so checkpoints. At each checkpoint, save all variables. This seems to be failing spectacularly. I'm sure I've messed up the phrasing, but I'm not sure how. Current format of those EVAL commands:

MC NAME: teaseStorage.setItem('yourname',yourname)
SAMPLE VARIABLE: teaseStorage.setItem('bi',bi)

Assign a value "checkpoint" which saves the location. This seems to work? It doesn't crash. But it doesn't work for the jump. See below:

checkpoint="morning1"

morning1 is the name of the page of the first checkpoint.

START

- On open, load all variables, starting with a counter that tells the player how many times they've played and the player's MC name. The counter seems to be working. The MC name doesn't.

COUNTER: var counter = teaseStorage.getItem("counter") ||0
MC NAME: yourname=teaseStorage.getItem('yourname')

- Load all other variables. I can't tell if this is working or not.

TYPICAL VARIABLES:

bi=teaseStorage.getItem('bi')
sub=teaseStorage.getItem('sub')
ass=teaseStorage.getItem('ass')

- Allow returning player to jump to their last saved checkpoint. Doesn't work. Freezes game. Command I'm using is:

pages.goto('checkpoint')

Can anyone tell me what I'm doing wrong? If you want to look at the entire tease:

https://milovana.com/webteases/showteas ... fe3c5d1f3a

Thanks in advance!

Re: Need help with saves!

Posted: Wed Aug 10, 2022 9:05 pm
by Thamrill
ritewriter wrote: Wed Aug 10, 2022 6:07 pm
Spoiler: show
Hi all,

Big favor to ask.

I am trying to add saves to my tease and failing miserably. If any of you have the time and expertise, would you be so kind as to look at my effort and tell me how to fix whatever is going wrong.

My save strategy is:

CHECKPOINTS

- Create a dozen or so checkpoints. At each checkpoint, save all variables. This seems to be failing spectacularly. I'm sure I've messed up the phrasing, but I'm not sure how. Current format of those EVAL commands:

MC NAME: teaseStorage.setItem('yourname',yourname)
SAMPLE VARIABLE: teaseStorage.setItem('bi',bi)

Assign a value "checkpoint" which saves the location. This seems to work? It doesn't crash. But it doesn't work for the jump. See below:

checkpoint="morning1"

morning1 is the name of the page of the first checkpoint.

START

- On open, load all variables, starting with a counter that tells the player how many times they've played and the player's MC name. The counter seems to be working. The MC name doesn't.

COUNTER: var counter = teaseStorage.getItem("counter") ||0
MC NAME: yourname=teaseStorage.getItem('yourname')

- Load all other variables. I can't tell if this is working or not.

TYPICAL VARIABLES:

bi=teaseStorage.getItem('bi')
sub=teaseStorage.getItem('sub')
ass=teaseStorage.getItem('ass')

- Allow returning player to jump to their last saved checkpoint. Doesn't work. Freezes game. Command I'm using is:

pages.goto('checkpoint')

Can anyone tell me what I'm doing wrong? If you want to look at the entire tease:

https://milovana.com/webteases/showteas ... fe3c5d1f3a

Thanks in advance!
One thing I noticed is that you save the counter way before the user enter their name. Hence if you restart the tease before the name is saved, it will default to the undefined name. I will look more into details tomorrow

Re: Need help with saves!

Posted: Wed Aug 10, 2022 10:08 pm
by ritewriter
Fixed that, thanks.

There's definitely a problem with how I'm writing out the set and get functions, since those both cause things to fail when I run them in test.

Re: Need help with saves!

Posted: Wed Aug 10, 2022 11:38 pm
by spaisin
ritewriter wrote: Wed Aug 10, 2022 6:07 pm pages.goto('checkpoint')
Isn't that trying to open a page named checkpoint? While a
pages.goto(checkpoint)
might be what you're looking for?

You have a "default 0" for your counter (that ||0), but not the other variables (you may have skipped mentioning them of course). But if your inits are not spot on, you might not have numbers to load, especially on a first run of a user. That leads to nulls, which need special treatment.

Re: Need help with saves!

Posted: Thu Aug 11, 2022 12:37 am
by ritewriter
spaisin wrote: Wed Aug 10, 2022 11:38 pm
ritewriter wrote: Wed Aug 10, 2022 6:07 pm pages.goto('checkpoint')
Isn't that trying to open a page named checkpoint? While a
pages.goto(checkpoint)
might be what you're looking for?
I'll try that. Thanks. Can it just be (checkpoint) if checkpoint is a defined variable? Or does it need to be (var checkpoint) or something?
You have a "default 0" for your counter (that ||0), but not the other variables (you may have skipped mentioning them of course). But if your inits are not spot on, you might not have numbers to load, especially on a first run of a user. That leads to nulls, which need special treatment.
I'll add that to all numeric variables. Does the rest of the format for the set and gets look right?

Also, if the variable is not numeric, like the name variable for example, do I still do ||0 or do I need to do ||null or ||"null" or something?

Also do I just as the ||0 to the gets? Or to the sets as well.

I really am hopeless with this stuff.

Thank you!

Re: Need help with saves!

Posted: Thu Aug 11, 2022 7:54 am
by Thamrill
ritewriter wrote: Thu Aug 11, 2022 12:37 am I'll try that. Thanks. Can it just be (checkpoint) if checkpoint is a defined variable? Or does it need to be (var checkpoint) or something?
If you already defined in the init the variable checkpoint, you just use checkpoint:

checkpoint=teaseStorage.getItem('checkpoint')

pages.goto(checkpoint)
ritewriter wrote: Thu Aug 11, 2022 12:37 am
You have a "default 0" for your counter (that ||0), but not the other variables (you may have skipped mentioning them of course). But if your inits are not spot on, you might not have numbers to load, especially on a first run of a user. That leads to nulls, which need special treatment.
It's not exactly super safe, but since they are loading the variable only after the first run (where all variables ought be set), the only variable that needs a default is the one counting runs.

ritewriter wrote: Thu Aug 11, 2022 12:37 am Also, if the variable is not numeric, like the name variable for example, do I still do ||0 or do I need to do ||null or ||"null" or something?


Also do I just as the ||0 to the gets? Or to the sets as well.
Only to get, as you are saying get the variable from the storage; if it is absent, set value to this. And it should be the same type of the original variable, so for example:

yourName=teaseStorage.getItem('yourName')||'Default name';

where you put a specific name in place of Default name, which is better, in case of error, than seeing undefined or null.

I'd suggest you to take a brief introductory course in javascript (there're tutorials on youtube), if you struggle with the fundamentals of EOS scripting. You can't find infos about the specific features of EOS (teaseStorage etc.), but you can understand better variables etc.

Also, I suggest you create a smaller tease where you can test and practice, before adding these modification to your bigger tease

Re: Need help with saves!

Posted: Thu Aug 11, 2022 4:32 pm
by ritewriter
Thamrill wrote: Thu Aug 11, 2022 7:54 am

I'd suggest you to take a brief introductory course in javascript (there're tutorials on youtube), if you struggle with the fundamentals of EOS scripting. You can't find infos about the specific features of EOS (teaseStorage etc.), but you can understand better variables etc.

Also, I suggest you create a smaller tease where you can test and practice, before adding these modification to your bigger tease
Thank you. I'll do that.

Re: Need help with saves!

Posted: Fri Aug 12, 2022 11:24 pm
by ritewriter
Still struggling with saves unfortunately.

I created a test tease. It's here:
https://milovana.com/webteases/showteas ... 4a7d33bec7

Storing and retrieving simple variable seems to be working fine.
Storing and retrieving string variables like 'yourname' is also working.

The only thing that's NOT working is the
pages.goto('checkpoint') command.
I've tried
pages.goto(checkpoint)
pages.goto('checkpoint')
pages.goto("checkpoint")

None of these work. I can do a work-around with IF/THEN if necessary, but it would be much easier if I could make pages.goto work.

Let me know if anyone has any suggestions. Thanks!

Re: Need help with saves!

Posted: Sat Aug 13, 2022 7:33 pm
by spaisin
Oh JS, how I love to hate you...

pages.goto("2")
works, goes to a page named 2

pages.goto(2)
doesn't work, just silently doesn't do anything

pages.goto(checkpoint)
when the checkpoint contains a number, it behaves like number, because of course
when it contains a string, it'll behave like a string

So, you can typecast your number into a string and it should work
pages.goto(String(checkpoint))
It did in my test...

And / or, you can give your pages string-names and the issue goes into a hiding-mode... :-)

Re: Need help with saves!

Posted: Mon Aug 15, 2022 4:38 pm
by ritewriter
spaisin wrote: Sat Aug 13, 2022 7:33 pm
So, you can typecast your number into a string and it should work
pages.goto(String(checkpoint))
It did in my test...

And / or, you can give your pages string-names and the issue goes into a hiding-mode... :-)
That worked! Thank you!

Re: Need help with saves!

Posted: Tue Aug 16, 2022 5:55 pm
by spaisin
ritewriter wrote: Mon Aug 15, 2022 4:38 pm That worked! Thank you!
Great :-) Yer welcome.

The power of shared "test code"; I wouldn't have guessed the issue from your text description, but seeing and testing the code made it pretty easy to spot.