Tease storage: saving score for next visit to same tease

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
jonasty01
Explorer
Explorer
Posts: 7
Joined: Thu Sep 10, 2020 6:09 am
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Tease storage: saving score for next visit to same tease

Post by jonasty01 »

Hi there

I,m making a tease in wich you have to increase score on every page to unlock a next page.
I have no clue on how to save the score for the next visit.

So far I manage to add it up over pages, but I dont manage to save it on a next visit.
I first put it in init script: score == 0 . But that makes the score reset on every visit right?
I've tried to put the save variables tutorial into my tease, but that doesnt seem to work either...

Basic idea: you can navigate to next or previous page and with the "if" boolean (if score>= ..) i determine if they can acces the page.

Hope you can help :/
User avatar
schefflera0101
Explorer At Heart
Explorer At Heart
Posts: 123
Joined: Wed Oct 07, 2020 12:21 pm
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Submissive

Re: Tease storage: saving score for next visit to same tease

Post by schefflera0101 »

Hi jonasty01,

You need to enable storage. Next write an init-code via:

var score = teaseStorage.getItem("score") || 0

This loads the score you have saved last time.
To save a score, you need to write an eval:

score=5
teaseStorage.setItem("score", score)

(instead of score=5 you can also write score=score+1 (adds 1 to your score))

I hope it helps you.
Try out my teases:
:love: Have fun! :love:

Older tease:
Edge slave training
Roblsforbobls
Explorer At Heart
Explorer At Heart
Posts: 260
Joined: Tue May 21, 2019 2:27 am
Gender: Male
Sexual Orientation: Asexual
I am a: Switch

Re: Tease storage: saving score for next visit to same tease

Post by Roblsforbobls »

schefflera0101 wrote: Thu Oct 28, 2021 4:52 pm (instead of score=5 you can also write score=score+1 (adds 1 to your score))
I think my favorite way to add or subtract one is using score++ and score--. Same thing as score = score + 1, but it's faster to type
bbman
Explorer
Explorer
Posts: 47
Joined: Fri Aug 16, 2013 6:38 pm
Gender: Male
Sexual Orientation: Straight

Re: Tease storage: saving score for next visit to same tease

Post by bbman »

I generally prefer a little more abstraction in the more tease specific parts, which can easily be obtained by wrapping your score storage within a player object:

Code: Select all

let player = {
    set score(value) {
        teaseStorage.setItem("score", value);
    },
    get score() {
        return teaseStorage.getItem("score") || 0;
    }
};
This allows you to write simple and readable code in the more important part of your tease logic, like below, and have your score saved across sessions automatically without having this save/load logic mixed in with the flow of your tease.

Examples:

Code: Select all

if (player.score >= nextPage.requiredScore) 
// unlock next page.
or

Code: Select all

if (playerAnswer == A)
    player.score++;
else if (playerAnswer == B)
    player.score = 0;
else if (playerAnswer == C)
    player.score -= 5;
Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests