Consider This!
The code console.log()
doesn’t use mySprite like ||sprites:say||
does. Why do you think that is?
“Hello World!” is a common first example used to introduce the syntax of a new programming language by showing a few words on a screen. In this activity we will display “Hello World!” on the game screen. Then we will modify our code to display in the Console Simulator environment.
In this activity, students will be introduced to:
||sprites:say||
console.log
(using JavaScript)||sprites:say||
Sprites have a method ||sprites:say||
that displays a text box over the sprite when used.
A method is an action that an object supports. For example, sprites (an object) have a ||sprites:say||
method that displays text provided above the sprite.
let msg: string = "Hello World!"
let mySprite: Sprite = null
mySprite = sprites.create(img`
. . . . . . . .
. . . . . . . .
6 6 6 6 6 6 6 6
6 f 6 6 6 6 f 6
6 6 6 a a 6 6 6
6 6 6 6 6 6 6 6
6 6 b b b b 6 6
6 6 6 6 6 6 6 6
`, SpriteKind.Player)
scene.setBackgroundColor(4)
mySprite.say(msg)
Identify and show the JavaScript code that aligns with which each block.
Example:
let msg: string = "Hello World!"
is equivalent to
let msg: string = "Hello World!"
Identify any JavaScript code that doesn’t seem to have any blocks directly related to it. Make a hypothesis of what it means does.
Example:
let mySprite: Sprite = null
This doesn’t have an equivalent block. To show this, we can copy and paste any block that we think it belongs to and when we look at the JavaScript, we’ll see that this code doesn’t repeat.
console
outputlet msg: string = "Hello World!"
console.log(msg)
console.log("msg sent!")
console.log( )
to “sprite hello”console.log()
for:||variables:msg||
variable from the prior example)||sprites:say||
message to have a conversation with the first sprite+
on the ||sprites:say||
block and set the time for each message to be displayed (1000 millisecond = 1 second)||sprites:say||
to make messages for all of themconsole.log()
has a larger limit on the length of text. Explain.