|
Javascript - increment index scripthello everyone again bouncing around javascript /* A simple script that takes two input values, sums them and returns the result. Special keywords for defining input and output key types: __boolean, __index, __number, __string, __image, __structure, __virtual Note that the function input arguments are read-only. */ var i = 0; function (__number index) main (__boolean up, __boolean down) { i++; var result = new Object(); if (up){ result.index = i++; } else if (down){ result.index = i--; } return result; } my idea is to hit the up key and down key and increment and decrement the index can anyone help? somehow this does not work thanks bern. |
See also the Counter patch.
those who know, know!
thank you.
bernardo i think your code should work, with the exception of the initial increment. your allocating i to 0 above your function, which is fine, but then in the first line of your function, it says i++; this will bump up your index to 1 before you evaluate your conditionals. so your first increment will have the equivalence of 2 when it should be 1. just thought i would point that out if your getting unexpected values.
you could also just use one conditional.....
if(up==true&&down!=true){++i}else{--i};
uau thanks dust. i was frying my brain for supper last night around that!. still i decided to keep the brain so that i could post here. thanks for the explanations. ++