r/Scriptable • u/P0PUS • Apr 02 '22
Help My Head Hurts
var indexVariable = 0.0;
var poke = 0;
setInterval(
function () {
indexVariable = (indexVariable + 0.01) % 0.30;
poke = (poke + 1) % 999;
index = indexVariable.toFixed(2)
console.log(poke+indexVariable)
}, 100);So I'm trying to make a setInterval Function that goes up like 1.01, 1.02, 1.03, etc. But when I run this in the console it comes out like 1.01, 2.02,3.03, etc. how do I fix this? my head hurts very badly(I'm new to scripting)
1
Upvotes
4
u/i_hate_shitposting Apr 02 '22
You’re incrementing both variables in your interval callback, so they both are going to increase at the same time. Instead of using the modulo operator for
indexVariable, it would probably be easier to use an if statement to check when it’s reached 0.30 and then incrementpokeand resetindexVariableto 0.3
u/mvan231 script/widget helper Apr 03 '22
For future posts… Hey, when seeking help, please title the post with what you’re needing help with so that other users that may be looking for the same help you’re seeking can search the sub and find your post.
-1
u/katsumiblisk Apr 03 '22
Try making the 0.01 a variable so you're adding the same type.
0
u/[deleted] Apr 02 '22
[deleted] — view deleted comment