diff --git a/js/Interpreter.js b/js/Interpreter.js index 83cdd11..f804f92 100644 --- a/js/Interpreter.js +++ b/js/Interpreter.js @@ -139,10 +139,11 @@ Interpreter.prototype.stepActiveThread = function() { // Advance the "program counter" to the next block before running the primitive. // Control flow primitives (e.g. if) may change activeThread.nextBlock. this.activeThread.nextBlock = b.nextBlock; - if(this.debugOps && this.debugFunc) { - var finalArgs = new Array(b.args.length); - for(var i=0; i 0) { b.tmp -= 1; // decrement count @@ -299,7 +327,7 @@ Interpreter.prototype.broadcast = function(b, waitFlag) { var receivers = []; var msg = String(interp.arg(b, 0)).toLowerCase(); var findReceivers = function(stack, target) { - if ((stack.op == "whenIReceive") && (stack.args[0].toLowerCase() == msg)) { + if ((stack.op == 'whenIReceive') && (stack.args[0].toLowerCase() == msg)) { receivers.push([stack, target]); } } @@ -334,10 +362,8 @@ Interpreter.prototype.isRunning = function(b) { Interpreter.prototype.startSubstack = function(b, isLoop, secondSubstack) { // Start the substack of a control structure command such as if or forever. - if (isLoop) { - b.isLoop = true; - this.activeThread.stack.push(b); // remember the block that started the substack - } + b.isLoop = !!isLoop; + this.activeThread.stack.push(b); // remember the block that started the substack if (!secondSubstack) { this.activeThread.nextBlock = b.substack; } else { diff --git a/js/primitives/LooksPrims.js b/js/primitives/LooksPrims.js index 174a4c7..5eb0835 100644 --- a/js/primitives/LooksPrims.js +++ b/js/primitives/LooksPrims.js @@ -18,35 +18,35 @@ var LooksPrims = function() {}; LooksPrims.prototype.addPrimsTo = function(primTable) { - primTable["show"] = this.primShow; - primTable["hide"] = this.primHide; + primTable['show'] = this.primShow; + primTable['hide'] = this.primHide; - primTable["nextCostume"] = this.primNextCostume; - primTable["lookLike:"] = this.primShowCostume; - primTable["costumeIndex"] = this.primCostumeNum; + primTable['nextCostume'] = this.primNextCostume; + primTable['lookLike:'] = this.primShowCostume; + primTable['costumeIndex'] = this.primCostumeNum; - primTable["nextScene"] = this.primNextCostume; - primTable["showBackground:"] = this.primShowCostume; - primTable["backgroundIndex"] = this.primCostumeNum; + primTable['nextScene'] = this.primNextCostume; + primTable['showBackground:'] = this.primShowCostume; + primTable['backgroundIndex'] = this.primCostumeNum; - primTable["startScene"] = this.primStartScene; - primTable["backgroundIndex"] = this.primCostumeNum; + primTable['startScene'] = this.primStartScene; + primTable['backgroundIndex'] = this.primCostumeNum; - primTable["changeSizeBy:"] = this.primChangeSize; - primTable["setSizeTo:"] = this.primSetSize; - primTable["scale"] = this.primSize; + primTable['changeSizeBy:'] = this.primChangeSize; + primTable['setSizeTo:'] = this.primSetSize; + primTable['scale'] = this.primSize; - primTable["comeToFront"] = this.primGoFront; - primTable["goBackByLayers:"] = this.primGoBack; + primTable['comeToFront'] = this.primGoFront; + primTable['goBackByLayers:'] = this.primGoBack; - primTable["changeGraphicEffect:by:"] = this.primChangeEffect; - primTable["setGraphicEffect:to:"] = this.primSetEffect; - primTable["filterReset"] = this.primClearEffects; + primTable['changeGraphicEffect:by:'] = this.primChangeEffect; + primTable['setGraphicEffect:to:'] = this.primSetEffect; + primTable['filterReset'] = this.primClearEffects; - primTable["say:"] = function(b) { showBubble(b, 'say'); }; - primTable["say:duration:elapsed:from:"] = function(b) { showBubbleAndWait(b, 'say'); }; - primTable["think:"] = function(b) { showBubble(b, 'think'); }; - primTable["think:duration:elapsed:from:"] = function(b) { showBubbleAndWait(b, 'think'); }; + primTable['say:'] = function(b) { showBubble(b, 'say'); }; + primTable['say:duration:elapsed:from:'] = function(b) { showBubbleAndWait(b, 'say'); }; + primTable['think:'] = function(b) { showBubble(b, 'think'); }; + primTable['think:duration:elapsed:from:'] = function(b) { showBubbleAndWait(b, 'think'); }; }; LooksPrims.prototype.primShow = function(b) { @@ -71,7 +71,7 @@ LooksPrims.prototype.primShowCostume = function(b) { if (typeof(arg) == 'number') { s.showCostume(arg - 1); } else { - if ((arg == 'CAMERA') || (arg == "CAMERA - MIRROR")) { + if ((arg == 'CAMERA') || (arg == 'CAMERA - MIRROR')) { s.showCostumeNamed(arg); return; } @@ -79,8 +79,8 @@ LooksPrims.prototype.primShowCostume = function(b) { if (i >= 0) { s.showCostume(i); } else { - var n = Number(arg); - if (!isNaN(n)) { + var n = parseInt(arg, 10); + if (n === n) { // if n is not NaN s.showCostume(n - 1); } else { return; // arg did not match a costume name nor is a valid number @@ -96,7 +96,7 @@ LooksPrims.prototype.primStartScene = function(b) { if (typeof(arg) == 'number') { s.showCostume(arg - 1); } else { - if ((arg == 'CAMERA') || (arg == "CAMERA - MIRROR")) { + if ((arg == 'CAMERA') || (arg == 'CAMERA - MIRROR')) { s.showCostumeNamed(arg); return; } @@ -104,8 +104,8 @@ LooksPrims.prototype.primStartScene = function(b) { if (i >= 0) { s.showCostume(i); } else { - var n = Number(arg); - if (!isNaN(n)) { + var n = parseInt(arg, 10); + if (n === n) { // fast !isNaN check s.showCostume(n - 1); } else { return; // arg did not match a costume name nor is a valid number @@ -123,14 +123,14 @@ LooksPrims.prototype.primCostumeNum = function(b) { LooksPrims.prototype.primChangeSize = function(b) { var s = interp.targetSprite(); if (s == null) return; - s.setSize(s.getSize() + interp.arg(b, 0)); + s.setSize(s.getSize() + interp.numarg(b, 0)); if (s.visible) interp.redraw(); }; LooksPrims.prototype.primSetSize = function(b) { var s = interp.targetSprite(); if (s == null) return; - s.setSize(interp.arg(b, 0)); + s.setSize(interp.numarg(b, 0)); if (s.visible) interp.redraw(); }; @@ -148,8 +148,8 @@ LooksPrims.prototype.primGoFront = function(b) { LooksPrims.prototype.primGoBack = function(b) { var s = interp.targetSprite(); - runtime.reassignZ(s, interp.arg(b, 0)); - if (s.visible) interp.redraw(); + runtime.reassignZ(s, interp.numarg(b, 0)); + if(s.visible) interp.redraw(); }; LooksPrims.prototype.primChangeEffect = function(b) {}; @@ -168,7 +168,7 @@ var showBubbleAndWait = function(b, type) { if (s == null) return; if (interp.activeThread.firstTime) { var text = interp.arg(b, 0); - var secs = interp.arg(b, 1); + var secs = interp.numarg(b, 1); s.showBubble(text, type); if (s.visible) interp.redraw(); interp.startTimer(secs); diff --git a/js/primitives/MotionAndPenPrims.js b/js/primitives/MotionAndPenPrims.js index 00345e9..f6fa8fa 100644 --- a/js/primitives/MotionAndPenPrims.js +++ b/js/primitives/MotionAndPenPrims.js @@ -22,42 +22,42 @@ MotionAndPenPrims.prototype.addPrimsTo = function(primTable) { primTable['turnLeft:'] = this.primTurnLeft; primTable['turnRight:'] = this.primTurnRight; primTable['heading:'] = this.primSetDirection; - primTable["pointTowards:"] = this.primPointTowards; - primTable["gotoX:y:"] = this.primGoTo; - primTable["gotoSpriteOrMouse:"] = this.primGoToSpriteOrMouse; - primTable["glideSecs:toX:y:elapsed:from:"] = this.primGlide; + primTable['pointTowards:'] = this.primPointTowards; + primTable['gotoX:y:'] = this.primGoTo; + primTable['gotoSpriteOrMouse:'] = this.primGoToSpriteOrMouse; + primTable['glideSecs:toX:y:elapsed:from:'] = this.primGlide; - primTable["changeXposBy:"] = this.primChangeX; - primTable["xpos:"] = this.primSetX; - primTable["changeYposBy:"] = this.primChangeY; - primTable["ypos:"] = this.primSetY; + primTable['changeXposBy:'] = this.primChangeX; + primTable['xpos:'] = this.primSetX; + primTable['changeYposBy:'] = this.primChangeY; + primTable['ypos:'] = this.primSetY; - primTable["bounceOffEdge"] = this.primBounceOffEdge; - primTable["setRotationStyle"] = this.primSetRotationStyle; + primTable['bounceOffEdge'] = this.primBounceOffEdge; + primTable['setRotationStyle'] = this.primSetRotationStyle; - primTable["xpos"] = this.primXPosition; - primTable["ypos"] = this.primYPosition; - primTable["heading"] = this.primDirection; + primTable['xpos'] = this.primXPosition; + primTable['ypos'] = this.primYPosition; + primTable['heading'] = this.primDirection; - primTable["clearPenTrails"] = this.primClear; - primTable["putPenDown"] = this.primPenDown; - primTable["putPenUp"] = this.primPenUp; - primTable["penColor:"] = this.primSetPenColor; - primTable["setPenHueTo:"] = this.primSetPenHue; - primTable["changePenHueBy:"] = this.primChangePenHue; - primTable["setPenShadeTo:"] = this.primSetPenShade; - primTable["changePenShadeBy:"] = this.primChangePenShade; - primTable["penSize:"] = this.primSetPenSize; - primTable["changePenSizeBy:"] = this.primChangePenSize; + primTable['clearPenTrails'] = this.primClear; + primTable['putPenDown'] = this.primPenDown; + primTable['putPenUp'] = this.primPenUp; + primTable['penColor:'] = this.primSetPenColor; + primTable['setPenHueTo:'] = this.primSetPenHue; + primTable['changePenHueBy:'] = this.primChangePenHue; + primTable['setPenShadeTo:'] = this.primSetPenShade; + primTable['changePenShadeBy:'] = this.primChangePenShade; + primTable['penSize:'] = this.primSetPenSize; + primTable['changePenSizeBy:'] = this.primChangePenSize; - primTable["stampCostume"] = this.primStamp; - primTable["stampTransparent"] = this.primStampTransparent; + primTable['stampCostume'] = this.primStamp; + primTable['stampTransparent'] = this.primStampTransparent; }; MotionAndPenPrims.prototype.primMove = function(b) { var s = interp.targetSprite(); var radians = (90 - s.direction) * Math.PI / 180; - var d = interp.arg(b, 0); + var d = interp.numarg(b, 0); moveSpriteTo(s, s.scratchX + d * Math.cos(radians), s.scratchY + d * Math.sin(radians)); if (s.visible) interp.redraw(); @@ -65,21 +65,21 @@ MotionAndPenPrims.prototype.primMove = function(b) { MotionAndPenPrims.prototype.primTurnLeft = function(b) { var s = interp.targetSprite(); - var d = s.direction - interp.arg(b, 0); + var d = s.direction - interp.numarg(b, 0); s.setDirection(d); if (s.visible) interp.redraw(); }; MotionAndPenPrims.prototype.primTurnRight = function(b) { var s = interp.targetSprite(); - var d = s.direction + interp.arg(b, 0); + var d = s.direction + interp.numarg(b, 0); s.setDirection(d); if (s.visible) interp.redraw(); }; MotionAndPenPrims.prototype.primSetDirection = function(b) { var s = interp.targetSprite(); - s.setDirection(interp.arg(b, 0)); + s.setDirection(interp.numarg(b, 0)); if (s.visible) interp.redraw(); }; @@ -96,7 +96,7 @@ MotionAndPenPrims.prototype.primPointTowards = function(b) { MotionAndPenPrims.prototype.primGoTo = function(b) { var s = interp.targetSprite(); - if (s != null) moveSpriteTo(s, interp.arg(b, 0), interp.arg(b, 1)); + if (s != null) moveSpriteTo(s, interp.numarg(b, 0), interp.numarg(b, 1)); }; MotionAndPenPrims.prototype.primGoToSpriteOrMouse = function(b) { @@ -110,9 +110,9 @@ MotionAndPenPrims.prototype.primGlide = function(b) { var s = interp.targetSprite(); if (s == null) return; if (interp.activeThread.firstTime) { - var secs = interp.arg(b, 0); - var destX = interp.arg(b, 1); - var destY = interp.arg(b, 2); + var secs = interp.numarg(b, 0); + var destX = interp.numarg(b, 1); + var destY = interp.numarg(b, 2); if (secs <= 0) { moveSpriteTo(s, destX, destY); return; @@ -138,22 +138,22 @@ MotionAndPenPrims.prototype.primGlide = function(b) { MotionAndPenPrims.prototype.primChangeX = function(b) { var s = interp.targetSprite(); - if (s != null) moveSpriteTo(s, s.scratchX + interp.arg(b, 0), s.scratchY); + if (s != null) moveSpriteTo(s, s.scratchX + interp.numarg(b, 0), s.scratchY); }; MotionAndPenPrims.prototype.primSetX = function(b) { var s = interp.targetSprite(); - if (s != null) moveSpriteTo(s, interp.arg(b, 0), s.scratchY); + if (s != null) moveSpriteTo(s, interp.numarg(b, 0), s.scratchY); }; MotionAndPenPrims.prototype.primChangeY = function(b) { var s = interp.targetSprite(); - if (s != null) moveSpriteTo(s, s.scratchX, s.scratchY + interp.arg(b, 0)); + if (s != null) moveSpriteTo(s, s.scratchX, s.scratchY + interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primSetY = function(b) { var s = interp.targetSprite(); - if (s != null) moveSpriteTo(s, s.scratchX, interp.arg(b, 0)); + if (s != null) moveSpriteTo(s, s.scratchX, interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primBounceOffEdge = function(b) { @@ -209,38 +209,38 @@ MotionAndPenPrims.prototype.primPenUp = function(b) { MotionAndPenPrims.prototype.primSetPenColor = function(b) { var s = interp.targetSprite(); - if (s != null) s.setPenColor(interp.arg(b, 0)); + if (s != null) s.setPenColor(interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primSetPenHue = function(b) { var s = interp.targetSprite(); - if (s != null) s.setPenHue(interp.arg(b, 0)); + if (s != null) s.setPenHue(interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primChangePenHue = function(b) { var s = interp.targetSprite(); - if (s != null) s.setPenHue(s.penHue + interp.arg(b, 0)); + if (s != null) s.setPenHue(s.penHue + interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primSetPenShade = function(b) { var s = interp.targetSprite(); - if (s != null) s.setPenShade(interp.arg(b, 0)); + if (s != null) s.setPenShade(interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primChangePenShade = function(b) { var s = interp.targetSprite(); - if (s != null) s.setPenShade(s.penShade + interp.arg(b, 0)); + if (s != null) s.setPenShade(s.penShade + interp.numarg(b, 0)); }; MotionAndPenPrims.prototype.primSetPenSize = function(b) { var s = interp.targetSprite(); - var w = Math.max(0, Math.min(interp.arg(b, 0), 100)); + var w = Math.max(0, Math.min(interp.numarg(b, 0), 100)); if (s != null) s.penWidth = w; }; MotionAndPenPrims.prototype.primChangePenSize = function(b) { var s = interp.targetSprite(); - var w = Math.max(0, Math.min(s.penWidth + interp.arg(b, 0), 100)); + var w = Math.max(0, Math.min(s.penWidth + interp.numarg(b, 0), 100)); if (s != null) s.penWidth = w; }; @@ -251,7 +251,7 @@ MotionAndPenPrims.prototype.primStamp = function(b) { MotionAndPenPrims.prototype.primStampTransparent = function(b) { var s = interp.targetSprite(); - var transparency = Math.max(0, Math.min(interp.arg(b, 0), 100)); + var transparency = Math.max(0, Math.min(interp.numarg(b, 0), 100)); var alpha = 100 - transparency; s.stamp(runtime.stage.lineCache, alpha); }; @@ -263,7 +263,7 @@ var stroke = function(s, oldX, oldY, newX, newY) { }; var mouseOrSpritePosition = function(arg) { - if (arg == "_mouse_") { + if (arg == '_mouse_') { var w = runtime.stage; return new Point(runtime.mousePos[0], runtime.mousePos[1]); } else { diff --git a/js/primitives/Primitives.js b/js/primitives/Primitives.js index 035cff7..6000f00 100644 --- a/js/primitives/Primitives.js +++ b/js/primitives/Primitives.js @@ -26,29 +26,29 @@ var Primitives = function() {} Primitives.prototype.addPrimsTo = function(primTable) { // Math primitives - primTable["+"] = function(b) { return interp.arg(b, 0) + interp.arg(b, 1); }; - primTable["-"] = function(b) { return interp.arg(b, 0) - interp.arg(b, 1); }; - primTable["*"] = function(b) { return interp.arg(b, 0) * interp.arg(b, 1); }; - primTable["/"] = function(b) { return interp.arg(b, 0) / interp.arg(b, 1); }; - primTable["%"] = function(b) { return interp.arg(b, 0) % interp.arg(b, 1); }; - primTable["randomFrom:to:"] = this.primRandom; - primTable["<"] = function(b) { return (interp.arg(b, 0) < interp.arg(b, 1)); }; - primTable["="] = function(b) { return (interp.arg(b, 0) == interp.arg(b, 1)); }; - primTable[">"] = function(b) { return (interp.arg(b, 0) > interp.arg(b, 1)); }; - primTable["&"] = function(b) { return interp.arg(b, 0) && interp.arg(b, 1); }; - primTable["|"] = function(b) { return interp.arg(b, 0) || interp.arg(b, 1); }; - primTable["not"] = function(b) { return !interp.arg(b, 0) }; - primTable["abs"] = function(b) { return Math.abs(interp.arg(b, 0)) }; - primTable["sqrt"] = function(b) { return Math.sqrt(interp.arg(b, 0)) }; + primTable['+'] = function(b) { return interp.numarg(b, 0) + interp.numarg(b, 1); }; + primTable['-'] = function(b) { return interp.numarg(b, 0) - interp.numarg(b, 1); }; + primTable['*'] = function(b) { return interp.numarg(b, 0) * interp.numarg(b, 1); }; + primTable['/'] = function(b) { return interp.numarg(b, 0) / interp.numarg(b, 1); }; + primTable['%'] = function(b) { return interp.numarg(b, 0) % interp.numarg(b, 1); }; + primTable['randomFrom:to:'] = this.primRandom; + primTable['<'] = function(b) { return (interp.numarg(b, 0) < interp.numarg(b, 1)); }; + primTable['='] = function(b) { return (interp.arg(b, 0) == interp.arg(b, 1)); }; + primTable['>'] = function(b) { return (interp.numarg(b, 0) > interp.numarg(b, 1)); }; + primTable['&'] = function(b) { return interp.boolarg(b, 0) && interp.boolarg(b, 1); }; + primTable['|'] = function(b) { return interp.boolarg(b, 0) || interp.boolarg(b, 1); }; + primTable['not'] = function(b) { return !interp.boolarg(b, 0); }; + primTable['abs'] = function(b) { return Math.abs(interp.numarg(b, 0)); }; + primTable['sqrt'] = function(b) { return Math.sqrt(interp.numarg(b, 0)); }; - primTable["\\\\"] = this.primModulo; - primTable["rounded"] = function(b) { return Math.round(interp.arg(b, 0)); }; - primTable["computeFunction:of:"] = this.primMathFunction; + primTable['\\\\'] = this.primModulo; + primTable['rounded'] = function(b) { return Math.round(interp.numarg(b, 0)); }; + primTable['computeFunction:of:'] = this.primMathFunction; // String primitives - primTable["concatenate:with:"] = function(b) { return "" + interp.arg(b, 0) + interp.arg(b, 1); }; - primTable["letter:of:"] = this.primLetterOf; - primTable["stringLength:"] = function(b) { return interp.arg(b, 0).length; }; + primTable['concatenate:with:'] = function(b) { return '' + interp.arg(b, 0) + interp.arg(b, 1); }; + primTable['letter:of:'] = this.primLetterOf; + primTable['stringLength:'] = function(b) { return interp.arg(b, 0).length; }; new VarListPrims().addPrimsTo(primTable); new MotionAndPenPrims().addPrimsTo(primTable); @@ -58,8 +58,8 @@ Primitives.prototype.addPrimsTo = function(primTable) { } Primitives.prototype.primRandom = function(b) { - var n1 = interp.arg(b, 0); - var n2 = interp.arg(b, 1); + var n1 = interp.numarg(b, 0); + var n2 = interp.numarg(b, 1); var low = n1 <= n2 ? n1 : n2; var hi = n1 <= n2 ? n2 : n1; if (low == hi) return low; @@ -72,34 +72,34 @@ Primitives.prototype.primRandom = function(b) { Primitives.prototype.primLetterOf = function(b) { var s = interp.arg(b, 1); - var i = interp.arg(b, 0) - 1; - if (i < 0 || i >= s.length) return ""; + var i = interp.numarg(b, 0) - 1; + if (i < 0 || i >= s.length) return ''; return s.charAt(i); } Primitives.prototype.primModulo = function(b) { - var modulus = interp.arg(b, 1); - var n = interp.arg(b, 0) % modulus; + var modulus = interp.numarg(b, 1); + var n = interp.numarg(b, 0) % modulus; if (n < 0) n += modulus; return n; } Primitives.prototype.primMathFunction = function(b) { - var op = interp.arg(b, 0); - var n = interp.arg(b, 1); + var op = interp.numarg(b, 0); + var n = interp.numarg(b, 1); switch(op) { - case "abs": return Math.abs(n); - case "sqrt": return Math.sqrt(n); - case "sin": return Math.sin(n * Math.PI / 180); - case "cos": return Math.cos(n * Math.PI / 180); - case "tan": return Math.tan(n * Math.PI / 180); - case "asin": return Math.asin(n) * 180 / Math.PI; - case "acos": return Math.acos(n) * 180 / Math.PI; - case "atan": return Math.atan(n) * 180 / Math.PI; - case "ln": return Math.log(n); - case "log": return Math.log(n) / Math.LN10; - case "e ^": return Math.exp(n); - case "10 ^": return Math.exp(n * Math.LN10); + case 'abs': return Math.abs(n); + case 'sqrt': return Math.sqrt(n); + case 'sin': return Math.sin(n * Math.PI / 180); + case 'cos': return Math.cos(n * Math.PI / 180); + case 'tan': return Math.tan(n * Math.PI / 180); + case 'asin': return Math.asin(n) * 180 / Math.PI; + case 'acos': return Math.acos(n) * 180 / Math.PI; + case 'atan': return Math.atan(n) * 180 / Math.PI; + case 'ln': return Math.log(n); + case 'log': return Math.log(n) / Math.LN10; + case 'e ^': return Math.exp(n); + case '10 ^': return Math.exp(n * Math.LN10); } return 0; } diff --git a/js/primitives/SoundPrims.js b/js/primitives/SoundPrims.js index a33f067..d1f4ce1 100644 --- a/js/primitives/SoundPrims.js +++ b/js/primitives/SoundPrims.js @@ -155,8 +155,8 @@ SoundPrims.prototype.primPlayNote = function(b) { var s = interp.targetSprite(); if (s == null) return; if (interp.activeThread.firstTime) { - var key = interp.arg(b, 0); - var secs = beatsToSeconds(interp.arg(b, 1)); + var key = interp.numarg(b, 0); + var secs = beatsToSeconds(interp.numarg(b, 1)); playNote(s.instrument, key, secs, s); interp.startTimer(secs); } else { @@ -168,8 +168,8 @@ SoundPrims.prototype.primPlayDrum = function(b) { var s = interp.targetSprite(); if (s == null) return; if (interp.activeThread.firstTime) { - var drum = Math.round(interp.arg(b, 0)); - var secs = beatsToSeconds(interp.arg(b, 1)); + var drum = Math.round(interp.numarg(b, 0)); + var secs = beatsToSeconds(interp.numarg(b, 1)); playDrum(drum, secs, s); interp.startTimer(secs); } else { @@ -181,7 +181,7 @@ SoundPrims.prototype.primPlayRest = function(b) { var s = interp.targetSprite(); if (s == null) return; if (interp.activeThread.firstTime) { - var secs = beatsToSeconds(interp.arg(b, 0)); + var secs = beatsToSeconds(interp.numarg(b, 0)); interp.startTimer(secs); } else { interp.checkTimer(); @@ -199,12 +199,12 @@ SoundPrims.prototype.primStopAllSounds = function(b) { SoundPrims.prototype.primChangeVolume = function(b) { var s = interp.targetSprite(); - if (s != null) s.volume += interp.arg(b, 0); + if (s != null) s.volume += interp.numarg(b, 0); }; SoundPrims.prototype.primSetVolume = function(b) { var s = interp.targetSprite(); - if (s != null) s.volume = interp.arg(b, 0); + if (s != null) s.volume = interp.numarg(b, 0); }; SoundPrims.prototype.primVolume = function(b) { diff --git a/js/primitives/VarListPrims.js b/js/primitives/VarListPrims.js index a8f734a..38b1f5b 100644 --- a/js/primitives/VarListPrims.js +++ b/js/primitives/VarListPrims.js @@ -67,11 +67,9 @@ VarListPrims.prototype.primChangeVar = function(b) { if (s == null) return; var targetVar = interp.arg(b, 0); if (targetVar in s.variables) { - s.variables[targetVar] = parseFloat(s.variables[targetVar]); - s.variables[targetVar] += interp.arg(b, 1); + s.variables[targetVar] = parseFloat(s.variables[targetVar]) + interp.numarg(b, 1); } else if (targetVar in runtime.stage.variables) { - runtime.stage.variables[targetVar] = parseFloat(runtime.stage.variables[targetVar]); - runtime.stage.variables[targetVar] += interp.arg(b, 1); + runtime.stage.variables[targetVar] = parseFloat(runtime.stage.variables[targetVar]) + interp.numarg(b, 1); } }; @@ -127,7 +125,7 @@ VarListPrims.prototype.primListDeleteLine = function(b) { var line = interp.arg(b, 0); if (line == 'all' || list.length == 0) list.length = 0; else if (line == 'last') list.splice(list.length - 1, 1); - else if (parseInt(line) - 1 in list) list.splice(parseInt(line) - 1, 1); + else if (parseInt(line, 10) - 1 in list) list.splice(parseInt(line, 10) - 1, 1); }; VarListPrims.prototype.primListInsertAt = function(b) { @@ -138,7 +136,7 @@ VarListPrims.prototype.primListInsertAt = function(b) { var position = interp.arg(b, 1); if (position == 'last') position = list.length; else if (position == 'random') position = Math.round(Math.random() * list.length); - else position = parseInt(position) - 1; + else position = parseInt(position, 10) - 1; if (position > list.length) return; list.splice(position, 0, newItem); @@ -152,7 +150,7 @@ VarListPrims.prototype.primListSetLine = function(b) { if (position == 'last') position = list.length - 1; else if (position == 'random') position = Math.floor(Math.random() * list.length); - else position = parseInt(position) - 1; + else position = parseInt(position, 10) - 1; if (position > list.length - 1) return;