Corrected casting numbers and fixed blocks under ifs not running

This commit is contained in:
MathWizz 2013-11-02 00:38:29 -05:00
parent d25c07538a
commit 2778e0a3fd
6 changed files with 107 additions and 82 deletions

View file

@ -139,13 +139,23 @@ Interpreter.prototype.stepActiveThread = function() {
b.primFcn(b); b.primFcn(b);
if (this.yield) { this.activeThread.nextBlock = b; return; } if (this.yield) { this.activeThread.nextBlock = b; return; }
b = this.activeThread.nextBlock; // refresh local variable b in case primitive did some control flow b = this.activeThread.nextBlock; // refresh local variable b in case primitive did some control flow
while (b == null) { while (!b) {
// end of a substack; pop the owning control flow block from stack // end of a substack; pop the owning control flow block from stack
// Note: This is a loop to handle nested control flow blocks. // Note: This is a loop to handle nested control flow blocks.
// yield at the end of a loop or when stack is empty
if (this.activeThread.stack.length === 0) {
this.activeThread.nextBlock = null;
return;
} else {
b = this.activeThread.stack.pop(); b = this.activeThread.stack.pop();
if ((b == null) || (b.isLoop)) { debugger;
this.activeThread.nextBlock = b; if (b.isLoop) {
return; // yield at the end of a loop or when stack is empty this.activeThread.nextBlock = b; // preserve where it left off
return;
} else {
b = b.nextBlock; // skip and continue for non looping blocks
}
} }
} }
} }
@ -195,6 +205,25 @@ Interpreter.prototype.arg = function(block, index) {
return arg; return arg;
} }
Interpreter.prototype.numarg = function(block, index) {
var arg = parseFloat(this.arg(block, index));
if (arg !== arg) {
return 0;
}
return arg;
}
Interpreter.prototype.boolarg = function(block, index) {
var arg = this.arg(block, index);
if (typeof arg === 'boolean') {
return arg;
} else if (typeof arg === 'string') {
return arg === '' || arg === '0' || arg.toLowerCase() === 'false';
}
return arg;
}
Interpreter.prototype.targetSprite = function() { Interpreter.prototype.targetSprite = function() {
return this.activeThread.target; return this.activeThread.target;
} }
@ -231,14 +260,14 @@ Interpreter.prototype.initPrims = function() {
this.primitiveTable['whenGreenFlag'] = this.primNoop; this.primitiveTable['whenGreenFlag'] = this.primNoop;
this.primitiveTable['whenKeyPressed'] = this.primNoop; this.primitiveTable['whenKeyPressed'] = this.primNoop;
this.primitiveTable['whenClicked'] = this.primNoop; this.primitiveTable['whenClicked'] = this.primNoop;
this.primitiveTable['if'] = function(b) { if (interp.arg(b, 0)) interp.startSubstack(b) }; this.primitiveTable['if'] = function(b) { if (interp.boolarg(b, 0)) interp.startSubstack(b) };
this.primitiveTable['doForever'] = function(b) { interp.startSubstack(b, true) }; this.primitiveTable['doForever'] = function(b) { interp.startSubstack(b, true) };
this.primitiveTable['doForeverIf'] = function(b) { if (interp.arg(b, 0)) interp.startSubstack(b, true); else interp.yield = true; }; this.primitiveTable['doForeverIf'] = function(b) { if (interp.boolarg(b, 0)) interp.startSubstack(b, true); else interp.yield = true; };
this.primitiveTable['doIf'] = function(b) { if (interp.arg(b, 0)) interp.startSubstack(b); }; this.primitiveTable['doIf'] = function(b) { if (interp.boolarg(b, 0)) interp.startSubstack(b); };
this.primitiveTable['doRepeat'] = this.primRepeat; this.primitiveTable['doRepeat'] = this.primRepeat;
this.primitiveTable['doIfElse'] = function(b) { if (interp.arg(b, 0)) interp.startSubstack(b); else interp.startSubstack(b, false, true); }; this.primitiveTable['doIfElse'] = function(b) { if (interp.boolarg(b, 0)) interp.startSubstack(b); else interp.startSubstack(b, false, true); };
this.primitiveTable['doWaitUntil'] = function(b) { if (!interp.arg(b, 0)) interp.yield = true }; this.primitiveTable['doWaitUntil'] = function(b) { if (!interp.boolarg(b, 0)) interp.yield = true };
this.primitiveTable['doUntil'] = function(b) { if (!interp.arg(b, 0)) interp.startSubstack(b, true) }; this.primitiveTable['doUntil'] = function(b) { if (!interp.boolarg(b, 0)) interp.startSubstack(b, true) };
this.primitiveTable['doReturn'] = function(b) { interp.activeThread = new Thread(null); }; this.primitiveTable['doReturn'] = function(b) { interp.activeThread = new Thread(null); };
this.primitiveTable['stopAll'] = function(b) { interp.activeThread = new Thread(null); interp.threads = []; } this.primitiveTable['stopAll'] = function(b) { interp.activeThread = new Thread(null); interp.threads = []; }
this.primitiveTable['whenIReceive'] = this.primNoop; this.primitiveTable['whenIReceive'] = this.primNoop;
@ -264,13 +293,13 @@ Interpreter.prototype.lookupPrim = function(op) {
Interpreter.prototype.primNoop = function(b) { console.log(b.op); } Interpreter.prototype.primNoop = function(b) { console.log(b.op); }
Interpreter.prototype.primWait = function(b) { Interpreter.prototype.primWait = function(b) {
if (interp.activeThread.firstTime) interp.startTimer(interp.arg(b, 0)); if (interp.activeThread.firstTime) interp.startTimer(interp.numarg(b, 0));
else interp.checkTimer(); else interp.checkTimer();
} }
Interpreter.prototype.primRepeat = function(b) { Interpreter.prototype.primRepeat = function(b) {
if (b.tmp == -1) { if (b.tmp == -1) {
b.tmp = Math.max(interp.arg(b, 0), 0); // Initialize repeat count on this block b.tmp = Math.max(interp.numarg(b, 0), 0); // Initialize repeat count on this block
} }
if (b.tmp > 0) { if (b.tmp > 0) {
b.tmp -= 1; // decrement count b.tmp -= 1; // decrement count
@ -323,10 +352,8 @@ Interpreter.prototype.isRunning = function(b) {
Interpreter.prototype.startSubstack = function(b, isLoop, secondSubstack) { Interpreter.prototype.startSubstack = function(b, isLoop, secondSubstack) {
// Start the substack of a control structure command such as if or forever. // Start the substack of a control structure command such as if or forever.
if (isLoop) { b.isLoop = !!isLoop;
b.isLoop = true;
this.activeThread.stack.push(b); // remember the block that started the substack this.activeThread.stack.push(b); // remember the block that started the substack
}
if(!secondSubstack) { if(!secondSubstack) {
this.activeThread.nextBlock = b.substack; this.activeThread.nextBlock = b.substack;
} else { } else {

View file

@ -79,8 +79,8 @@ LooksPrims.prototype.primShowCostume = function(b) {
if (i >= 0) { if (i >= 0) {
s.showCostume(i); s.showCostume(i);
} else { } else {
var n = Number(arg); var n = parseInt(arg, 10);
if (!isNaN(n)) { if (n === n) { // if n is not NaN
s.showCostume(n - 1); s.showCostume(n - 1);
} else { } else {
return; // arg did not match a costume name nor is a valid number return; // arg did not match a costume name nor is a valid number
@ -104,8 +104,8 @@ LooksPrims.prototype.primStartScene = function(b) {
if (i >= 0) { if (i >= 0) {
s.showCostume(i); s.showCostume(i);
} else { } else {
var n = Number(arg); var n = parseInt(arg, 10);
if (!isNaN(n)) { if (n === n) { // fast !isNaN check
s.showCostume(n - 1); s.showCostume(n - 1);
} else { } else {
return; // arg did not match a costume name nor is a valid number 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) { LooksPrims.prototype.primChangeSize = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; 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(); if (s.visible) interp.redraw();
} }
LooksPrims.prototype.primSetSize = function(b) { LooksPrims.prototype.primSetSize = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; if (s == null) return;
s.setSize(interp.arg(b, 0)); s.setSize(interp.numarg(b, 0));
if (s.visible) interp.redraw(); if (s.visible) interp.redraw();
} }
@ -148,7 +148,7 @@ LooksPrims.prototype.primGoFront = function(b) {
LooksPrims.prototype.primGoBack = function(b) { LooksPrims.prototype.primGoBack = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
runtime.reassignZ(s, interp.arg(b, 0)); runtime.reassignZ(s, interp.numarg(b, 0));
if(s.visible) interp.redraw(); if(s.visible) interp.redraw();
} }
@ -168,7 +168,7 @@ var showBubbleAndWait = function(b, type) {
if (s == null) return; if (s == null) return;
if (interp.activeThread.firstTime) { if (interp.activeThread.firstTime) {
var text = interp.arg(b, 0); var text = interp.arg(b, 0);
var secs = interp.arg(b, 1); var secs = interp.numarg(b, 1);
s.showBubble(text, type); s.showBubble(text, type);
if (s.visible) interp.redraw(); if (s.visible) interp.redraw();
interp.startTimer(secs); interp.startTimer(secs);

View file

@ -57,7 +57,7 @@ MotionAndPenPrims.prototype.addPrimsTo = function(primTable) {
MotionAndPenPrims.prototype.primMove = function(b) { MotionAndPenPrims.prototype.primMove = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
var radians = ((Math.PI * (90 - s.direction)) / 180); var radians = ((Math.PI * (90 - s.direction)) / 180);
var d = interp.arg(b, 0); var d = interp.numarg(b, 0);
moveSpriteTo(s, s.scratchX + (d * Math.cos(radians)), moveSpriteTo(s, s.scratchX + (d * Math.cos(radians)),
s.scratchY + (d * Math.sin(radians))); s.scratchY + (d * Math.sin(radians)));
@ -66,28 +66,28 @@ MotionAndPenPrims.prototype.primMove = function(b) {
MotionAndPenPrims.prototype.primTurnLeft = function(b) { MotionAndPenPrims.prototype.primTurnLeft = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
var d = s.direction - interp.arg(b, 0); var d = s.direction - interp.numarg(b, 0);
s.setDirection(d); s.setDirection(d);
if(s.visible) interp.redraw(); if(s.visible) interp.redraw();
} }
MotionAndPenPrims.prototype.primTurnRight = function(b) { MotionAndPenPrims.prototype.primTurnRight = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
var d = s.direction + interp.arg(b, 0); var d = s.direction + interp.numarg(b, 0);
s.setDirection(d); s.setDirection(d);
if(s.visible) interp.redraw(); if(s.visible) interp.redraw();
} }
MotionAndPenPrims.prototype.primSetDirection = function(b) { MotionAndPenPrims.prototype.primSetDirection = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
s.setDirection(interp.arg(b, 0)); s.setDirection(interp.numarg(b, 0));
if(s.visible) interp.redraw(); if(s.visible) interp.redraw();
} }
MotionAndPenPrims.prototype.primPointTowards = function(b) { MotionAndPenPrims.prototype.primPointTowards = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
var p = mouseOrSpritePosition(interp.arg(b, 0)); var p = mouseOrSpritePosition(interp.numarg(b, 0));
if ((s == null) || (p == null)) return; if (s == null) return;
var dx = p.x - s.scratchX; var dx = p.x - s.scratchX;
var dy = p.y - s.scratchY; var dy = p.y - s.scratchY;
var angle = 90 - ((Math.atan2(dy, dx) * 180) / Math.PI); var angle = 90 - ((Math.atan2(dy, dx) * 180) / Math.PI);
@ -97,7 +97,7 @@ MotionAndPenPrims.prototype.primPointTowards = function(b) {
MotionAndPenPrims.prototype.primGoTo = function(b) { MotionAndPenPrims.prototype.primGoTo = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primGoToSpriteOrMouse = function(b) {
@ -111,9 +111,9 @@ MotionAndPenPrims.prototype.primGlide = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; if (s == null) return;
if (interp.activeThread.firstTime) { if (interp.activeThread.firstTime) {
var secs = interp.arg(b, 0); var secs = interp.numarg(b, 0);
var destX = interp.arg(b, 1); var destX = interp.numarg(b, 1);
var destY = interp.arg(b, 2); var destY = interp.numarg(b, 2);
if (secs <= 0) { if (secs <= 0) {
moveSpriteTo(s, destX, destY); moveSpriteTo(s, destX, destY);
return; return;
@ -140,22 +140,22 @@ MotionAndPenPrims.prototype.primGlide = function(b) {
MotionAndPenPrims.prototype.primChangeX = function(b) { MotionAndPenPrims.prototype.primChangeX = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primSetX = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primChangeY = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primSetY = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primBounceOffEdge = function(b) {
@ -211,38 +211,38 @@ MotionAndPenPrims.prototype.primPenUp = function(b) {
MotionAndPenPrims.prototype.primSetPenColor = function(b) { MotionAndPenPrims.prototype.primSetPenColor = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primSetPenHue = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primChangePenHue = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primSetPenShade = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primChangePenShade = function(b) {
var s = interp.targetSprite(); 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) { MotionAndPenPrims.prototype.primSetPenSize = function(b) {
var s = interp.targetSprite(); 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; if (s != null) s.penWidth = w;
} }
MotionAndPenPrims.prototype.primChangePenSize = function(b) { MotionAndPenPrims.prototype.primChangePenSize = function(b) {
var s = interp.targetSprite(); 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; if (s != null) s.penWidth = w;
} }
@ -253,7 +253,7 @@ MotionAndPenPrims.prototype.primStamp = function(b) {
MotionAndPenPrims.prototype.primStampTransparent = function(b) { MotionAndPenPrims.prototype.primStampTransparent = function(b) {
var s = interp.targetSprite(); 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; var alpha = 100 - transparency;
s.stamp(runtime.stage.lineCache, alpha); s.stamp(runtime.stage.lineCache, alpha);
} }

View file

@ -26,23 +26,23 @@ var Primitives = function() {}
Primitives.prototype.addPrimsTo = function(primTable) { Primitives.prototype.addPrimsTo = function(primTable) {
// Math primitives // Math primitives
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.arg(b, 0) - interp.arg(b, 1) }; 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.arg(b, 0) / interp.arg(b, 1) }; 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["randomFrom:to:"] = this.primRandom; primTable["randomFrom:to:"] = this.primRandom;
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.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.numarg(b, 0) > interp.numarg(b, 1)) };
primTable["&"] = function(b) { return interp.arg(b, 0) && interp.arg(b, 1) }; primTable["&"] = function(b) { return interp.boolarg(b, 0) && interp.boolarg(b, 1) };
primTable["|"] = function(b) { return interp.arg(b, 0) || interp.arg(b, 1) }; primTable["|"] = function(b) { return interp.boolarg(b, 0) || interp.boolarg(b, 1) };
primTable["not"] = function(b) { return !interp.arg(b, 0) }; primTable["not"] = function(b) { return !interp.boolarg(b, 0) };
primTable["abs"] = function(b) { return Math.abs(interp.arg(b, 0)) }; primTable["abs"] = function(b) { return Math.abs(interp.numarg(b, 0)) };
primTable["sqrt"] = function(b) { return Math.sqrt(interp.arg(b, 0)) }; primTable["sqrt"] = function(b) { return Math.sqrt(interp.numarg(b, 0)) };
primTable["\\\\"] = this.primModulo; primTable["\\\\"] = this.primModulo;
primTable["rounded"] = function(b) { return Math.round(interp.arg(b, 0)) }; primTable["rounded"] = function(b) { return Math.round(interp.numarg(b, 0)) };
primTable["computeFunction:of:"] = this.primMathFunction; primTable["computeFunction:of:"] = this.primMathFunction;
// String primitives // String primitives
@ -58,8 +58,8 @@ Primitives.prototype.addPrimsTo = function(primTable) {
} }
Primitives.prototype.primRandom = function(b) { Primitives.prototype.primRandom = function(b) {
var n1 = interp.arg(b, 0); var n1 = interp.numarg(b, 0);
var n2 = interp.arg(b, 1); var n2 = interp.numarg(b, 1);
var low = (n1 <= n2) ? n1 : n2; var low = (n1 <= n2) ? n1 : n2;
var hi = (n1 <= n2) ? n2 : n1; var hi = (n1 <= n2) ? n2 : n1;
if(low == hi) return low; if(low == hi) return low;
@ -72,21 +72,21 @@ Primitives.prototype.primRandom = function(b) {
Primitives.prototype.primLetterOf = function(b) { Primitives.prototype.primLetterOf = function(b) {
var s = interp.arg(b, 1); var s = interp.arg(b, 1);
var i = interp.arg(b, 0) - 1; var i = interp.numarg(b, 0) - 1;
if ((i < 0) || (i >= s.length)) return ""; if ((i < 0) || (i >= s.length)) return "";
return s.charAt(i); return s.charAt(i);
} }
Primitives.prototype.primModulo = function(b) { Primitives.prototype.primModulo = function(b) {
var modulus = interp.arg(b, 1); var modulus = interp.numarg(b, 1);
var n = interp.arg(b, 0) % modulus; var n = interp.numarg(b, 0) % modulus;
if (n < 0) n += modulus; if (n < 0) n += modulus;
return n; return n;
} }
Primitives.prototype.primMathFunction = function(b) { Primitives.prototype.primMathFunction = function(b) {
var op = interp.arg(b, 0); var op = interp.numarg(b, 0);
var n = interp.arg(b, 1); var n = interp.numarg(b, 1);
switch(op) { switch(op) {
case "abs": return Math.abs(n); case "abs": return Math.abs(n);
case "sqrt": return Math.sqrt(n); case "sqrt": return Math.sqrt(n);

View file

@ -155,8 +155,8 @@ SoundPrims.prototype.primPlayNote = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; if (s == null) return;
if (interp.activeThread.firstTime) { if (interp.activeThread.firstTime) {
var key = interp.arg(b, 0); var key = interp.numarg(b, 0);
var secs = beatsToSeconds(interp.arg(b, 1)); var secs = beatsToSeconds(interp.numarg(b, 1));
playNote(s.instrument, key, secs, s); playNote(s.instrument, key, secs, s);
interp.startTimer(secs); interp.startTimer(secs);
} else { } else {
@ -168,8 +168,8 @@ SoundPrims.prototype.primPlayDrum = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; if (s == null) return;
if (interp.activeThread.firstTime) { if (interp.activeThread.firstTime) {
var drum = Math.round(interp.arg(b, 0)); var drum = Math.round(interp.numarg(b, 0));
var secs = beatsToSeconds(interp.arg(b, 1)); var secs = beatsToSeconds(interp.numarg(b, 1));
playDrum(drum, secs, s); playDrum(drum, secs, s);
interp.startTimer(secs); interp.startTimer(secs);
} else { } else {
@ -181,7 +181,7 @@ SoundPrims.prototype.primPlayRest = function(b) {
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s == null) return; if (s == null) return;
if (interp.activeThread.firstTime) { if (interp.activeThread.firstTime) {
var secs = beatsToSeconds(interp.arg(b, 0)); var secs = beatsToSeconds(interp.numarg(b, 0));
interp.startTimer(secs); interp.startTimer(secs);
} else { } else {
interp.checkTimer(); interp.checkTimer();
@ -199,12 +199,12 @@ SoundPrims.prototype.primStopAllSounds = function(b) {
SoundPrims.prototype.primChangeVolume = function(b) { SoundPrims.prototype.primChangeVolume = function(b) {
var s = interp.targetSprite(); 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) { SoundPrims.prototype.primSetVolume = function(b) {
var s = interp.targetSprite(); 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) { SoundPrims.prototype.primVolume = function(b) {

View file

@ -63,11 +63,9 @@ VarListPrims.prototype.primChangeVar = function(b) {
if (s == null) return; if (s == null) return;
var targetVar = interp.arg(b, 0); var targetVar = interp.arg(b, 0);
if (targetVar in s.variables) { if (targetVar in s.variables) {
s.variables[targetVar] = parseFloat(s.variables[targetVar]); s.variables[targetVar] = parseFloat(s.variables[targetVar]) + interp.numarg(b, 1);
s.variables[targetVar] += interp.arg(b, 1);
} else if (targetVar in runtime.stage.variables) { } else if (targetVar in runtime.stage.variables) {
runtime.stage.variables[targetVar] = parseFloat(runtime.stage.variables[targetVar]); runtime.stage.variables[targetVar] = parseFloat(runtime.stage.variables[targetVar]) + interp.numarg(b, 1);
runtime.stage.variables[targetVar] += interp.arg(b, 1);
} }
} }
@ -123,7 +121,7 @@ VarListPrims.prototype.primListDeleteLine = function(b) {
var line = interp.arg(b, 0); var line = interp.arg(b, 0);
if (line == 'all' || list.length == 0) list.length = 0; if (line == 'all' || list.length == 0) list.length = 0;
else if (line == 'last') list.splice(list.length - 1, 1); 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) { VarListPrims.prototype.primListInsertAt = function(b) {
@ -134,7 +132,7 @@ VarListPrims.prototype.primListInsertAt = function(b) {
var position = interp.arg(b, 1); var position = interp.arg(b, 1);
if (position == 'last') position = list.length; if (position == 'last') position = list.length;
else if (position == 'random') position = Math.round(Math.random() * 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; if (position > list.length) return;
list.splice(position, 0, newItem); list.splice(position, 0, newItem);
@ -148,7 +146,7 @@ VarListPrims.prototype.primListSetLine = function(b) {
if (position == 'last') position = list.length - 1; if (position == 'last') position = list.length - 1;
else if (position == 'random') position = Math.floor(Math.random() * list.length); 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; if (position > list.length - 1) return;
list[position] = newItem; list[position] = newItem;