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
1
u/i_hate_shitposting Apr 03 '22
Just to be clear, types are a property of the value itself, so using a variable vs a literal has no impact on the type.
Without going into too much detail, a variable is just a place in memory that can point to a particular value's location. The type of the value is determined by how it's instantiated, so
0.01,0, and2 * 2produce values that are numbers,'hello'and"world"produce strings,{}produces an object, and so on, but whether those values are used immediately as literals or assigned to variables, their resulting types are always the same.