Skip to content

Commit 1f07eb1

Browse files
committed
Merge pull request scratchfoundation#188 from nathan/duplicate-ask
Fixed ask prompting multiple times for the same script
2 parents ab25a08 + efd4600 commit 1f07eb1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/interpreter/Interpreter.as

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class Interpreter {
8181
private var warpThread:Thread; // thread that is in warp mode
8282
private var warpBlock:Block; // proc call block that entered warp mode
8383

84+
public var askThread:Thread; // thread that opened the ask prompt
85+
8486
protected var debugFunc:Function;
8587

8688
public function Interpreter(app:Scratch) {
@@ -170,6 +172,7 @@ public class Interpreter {
170172
var wasRunning:Boolean = false;
171173
for (var i:int = 0; i < threads.length; i++) {
172174
if ((threads[i].topBlock == b) && (threads[i].target == targetObj)) {
175+
if (askThread == threads[i]) app.runtime.clearAskPrompts();
173176
threads[i] = newThread;
174177
wasRunning = true;
175178
}

src/primitives/SensingPrims.as

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ public class SensingPrims {
306306
var obj:ScratchObj = interp.targetObj();
307307
if (obj) app.runtime.showVarOrListFor(interp.arg(b, 0), true, obj);
308308
}
309-
309+
310310
private function primHideListWatcher(b:Block):* {
311311
var obj:ScratchObj = interp.targetObj();
312312
if (obj) app.runtime.hideVarOrListFor(interp.arg(b, 0), true, obj);
313313
}
314-
314+
315315
private function primTimestamp(b:Block):* {
316316
const millisecondsPerDay:int = 24 * 60 * 60 * 1000;
317317
const epoch:Date = new Date(2000, 0, 1); // Jan 1, 2000 (Note: Months are zero-based.)

src/scratch/ScratchRuntime.as

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ public class ScratchRuntime {
462462

463463
public function showAskPrompt(question:String = ''):void {
464464
var p:AskPrompter = new AskPrompter(question, app);
465+
interp.askThread = interp.activeThread;
465466
p.x = 15;
466467
p.y = ScratchObj.STAGEH - p.height - 5;
467468
app.stagePane.addChild(p);
468469
setTimeout(p.grabKeyboardFocus, 100); // work-dround for Window keyboard event handling
469470
}
470471

471472
public function hideAskPrompt(p:AskPrompter):void {
473+
interp.askThread = null;
472474
lastAnswer = p.answer();
473475
p.parent.removeChild(p);
474476
app.stage.focus = null;
@@ -484,6 +486,7 @@ public class ScratchRuntime {
484486
}
485487

486488
public function clearAskPrompts():void {
489+
interp.askThread = null;
487490
var allPrompts:Array = [];
488491
var uiLayer:Sprite = app.stagePane.getUILayer();
489492
var c:DisplayObject;

0 commit comments

Comments
 (0)