From 6083f4dcd72253a86a0d047e394a3e0cf3aa6ce4 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 14 Aug 2020 18:04:55 -0500 Subject: [PATCH] Expose last key pressed to scripts --- src/compiler/astgen.js | 14 +++++++------- src/compiler/jsgen.js | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compiler/astgen.js b/src/compiler/astgen.js index 94e81473..db2d0b40 100644 --- a/src/compiler/astgen.js +++ b/src/compiler/astgen.js @@ -158,14 +158,14 @@ class ScriptTreeGenerator { }; case 'argument_reporter_string_number': { - if (!this.isProcedure) { - return { - kind: 'constant', - value: 0 - }; - } const name = block.fields.VALUE.value; - if (!this.procedureArguments.includes(name)) { + if (!this.isProcedure || !this.procedureArguments.includes(name)) { + // Not final. + if (name === 'last key pressed') { + return { + kind: 'tw.lastKeyPressed' + }; + } return { kind: 'constant', value: 0 diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index 9b6116ca..714de3d7 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -277,6 +277,10 @@ class ScriptCompiler { case 'sensing.username': return new TypedInput('ioQuery("userData", "getUsername")', TYPE_STRING); + case 'tw.lastKeyPressed': + // Not final. + return new TypedInput('ioQuery("keyboard", "getLastKeyPressed")', TYPE_STRING); + case 'var.get': return new TypedInput(`${this.referenceVariable(node.variable)}.value`, TYPE_UNKNOWN);