Scratch-vm: Variable stops increasing eventually, but should go up to "infinity"

Created on 12 Jun 2017  路  4Comments  路  Source: LLK/scratch-vm

Expected Behavior

The value should go up until it displays "infinity"; it shouldn't get stuck at a specific numerical value and stop increasing.

Actual Behavior

The value gets fairly large quickly in the stack as shown, then slows down in its rate of increase. If you edit the value in the forever loop for how much the value is increasing by, you can lower the value to get the increase of the variable to speed up again. Eventually the value of the variable stops increasing at all, even if you lower the rate of change back to 1. However, you can get to a much larger value if you change what values are in the loop.

Steps to Reproduce

  • Add a new variable
  • Drag out the blocks as shown in the screenshots for Stack 1
  • Click to start the stack
  • While the stack is active, edit the values in the pick random block to change how quickly the variable value increases
  • Eventually the value will get "stuck"
  • Then even if you lower the values in the pick random block, it will remain stuck
  • If you change to Stack 2, note you can get to a much larger value

    • We should probably be consistent

Stack 1
screen shot 2017-06-12 at 1 20 56 pm
screen shot 2017-06-12 at 12 46 03 pm

Stack 2
Increasing the number of 0's in the divisor:
screen shot 2017-06-12 at 2 04 30 pm
screen shot 2017-06-12 at 2 29 32 pm

I may have hit some kind of limit eventually - after I dropped the block stack in the toolbox and it was deleted, I noticed the variable value was "infinity":
screen shot 2017-06-12 at 2 33 15 pm
screen shot 2017-06-12 at 2 31 43 pm

Operating System and Browser

_Mac OS El Capitan, Chrome 59_

bug help wanted

All 4 comments

I'd prefer no limit until JS hits infinity -- that's the same as it is in 2.0, and it allows for more precise math. Maybe show fewer significant digits if it's in e-notation?

I did eventually hit "Infinity" as a value with Stack 2, so maybe the question in this case shouldn't be whether there should be a size limit (it should just be "infinity"), but instead to investigate why Stack 1 stops increasing the variable value at some point - maybe that's just the bug...

This is because, for int input, random returns:
return low + parseInt(Math.random() * (high + 1 - low), 10);
But to quote the JS specs for parseInt:

Because some numbers include the e character in their string representation (e.g. 6.022e23), using parseInt to truncate numeric values will produce unexpected results when used on very large or very small numbers. parseInt should not be used as a substitute for Math.floor().

To solve this problem you must deal with it as a string.

Wait, why is parseInt being used for rounding?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rasmushaglund picture rasmushaglund  路  4Comments

cwillisf picture cwillisf  路  4Comments

ZenithRogue picture ZenithRogue  路  8Comments

apple502j picture apple502j  路  6Comments

thisandagain picture thisandagain  路  5Comments