How to add persistence to the multiple slider script

I have a multiple slider script made by Tomas Pietravallo and I have a persistence script that I found on youtube. I tried to just put the two scripts in the filter but its not saving the slider values after I take a photo. I am a noob with scripts so if any one could help me with this.

I am using this script multiple sliders script

Hi @JhonyAugusto ,
Funny you mention it I was planning to add that. I quickly made that script for you but was planning to refine it and publish it here as a resource later, the competition took time away from that but I’ll probably do it this weekend. If you want to try ti make it your self, I’d push the whole object to a persistence key and then retrieve it.

3 Likes

I tried to understand the logic, I tried to combine parts of both scripts but I dont have enough script knowledge to rewrite and make it work.

Okey, give me 5m and I’ll do it.

5 spark minutes = 30 normal people minutes

1 Like

@JhonyAugusto could you confirm if the script works for your needs? I updated the repo.
Remember to whitelist the keys, Project capabilities > +Persistence > Type the key. You can change the key on line 13 :wink:

1 Like

The sliders disappeared with the new script. I have to use the other script from the slider folder ?

They are the same… weird, I’ll try to fix the bug

Maybe this is a bug? I’ve tried making persistence() return a fulfilled promise so the setUpPicker() which wasn’t modified gets executed and either way I get the same error. It’s really weird cause it fails in a pattern (I get: shows up-fail-shows up-fail-shows-up) which would make sense if persistence played some rol in the whole thing but as I said I’ve tried cancelling out persistence() and I still get the error.

On my phone I get the pattern described above with fail being the slider and picker failing to load, but on spark (the computer) it loads correctly every time, which to me suggests there’s an error in the Spark AR Player App (at least iOS) - I haven’t tried sending to Instagram via test link.

I’ll report it, hopefully it gets solved quickly

Maybe there is more than one way to write the script. The one I use is this:

const D = require(‘Diagnostics’)
const R = require(‘Reactive’)
const {slider, picker} = require(‘NativeUI’)
const Textures = require(‘Textures’)
const Persistence = require(‘Persistence’)
const Time = require(‘Time’)

// get the saved picker selectedIndex
Persistence.userScope.get(‘picker’).then((data) => {
D.log('Persistence.userScope.get(“picker”): ’ + data.selectedIndex)
picker.selectedIndex = R.val(data.selectedIndex)
}).catch(error => {
D.log(‘failed to get saved picker value’)
D.log(error)
})
// SLIDER
slider.visible = R.val(true)

// watch for slider changes and store the value
slider.value.monitor().subscribe(({newValue}) => {
D.log('slider: ’ + newValue)
const data = {value: newValue}
Persistence.userScope.set(‘slider’, data).catch(error => {
D.log(‘failed to save slider value’)
D.log(error)
})
})

// get the saved slider value
Persistence.userScope.get(‘slider’).then(data => {
slider.value = R.val(data.value)
}).catch(error => {
D.log(‘failed to get saved slider value’)
D.log(error)
// default
slider.value = R.val(.5)
})

Or maybe there is a bug I am not sure.

1 Like

Yes, there are many ways to write the same thing.
But, do you remember the original script I made? You can use this link to see the old version, I just tested that code that was working perfectly fine and I get the same error - and the same working/not working pattern, so it’s definitely a bug :confused:, we can only hope the bug report gets noticed…

Btw reach out if you ever need help, I’m sort of new too

1 Like

I saw two filters using multiple picker with persistence I will talk to the creators to try get the solution. I will share with you here if I discover anything.

1 Like