global LF
global cx
----------------------------------------
--
----------------------------------------
on startMovie
_movie.stage.rect = rect(0, 0, 320, 240).offset(20, 34)
cx = xtra("console").new()
LF = numToChar(10)
x = 70
w = 180
sn = 1
y = 10
dy = 30
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Print to StdOut (green)"
m.scriptText = "on mouseUp"&RETURN&"testStdOut()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Print to StdErr (red)"
m.scriptText = "on mouseUp"&RETURN&"testStdErr()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Test stdIn input (blocking!)"
m.scriptText = "on mouseUp"&RETURN&"testStdIn()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Trigger script error"
m.scriptText = "on mouseUp"&RETURN&"x = 1/0"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Change console font"
m.scriptText = "on mouseUp"&RETURN&"testFont()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Clear console window"
m.scriptText = "on mouseUp"&RETURN&"_global.cx.consoleClear()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
m = new(#button)
m.rect = rect(0, 0, w, 0)
m.alignment = "center"
m.text = "Start REPL" & RETURN & "(interactive input-output loop)"
m.scriptText = "on mouseUp"&RETURN&"testRepl()"&RETURN&"end"
_movie.puppetSprite(sn, TRUE)
sprite(sn).member = m
sprite(sn).loc = point(x, y)
y = y + dy
sn = sn + 1
_movie.updateStage()
if cx.consoleExists() then
-- if the projector was started in a console, attach this console
cx.consoleAttach()
else
-- otherwise create a new console window
cx.consoleCreate()
end if
-- change console title (optional)
cx.consoleSetTitle("Fancy Lingo Console")
-- Windows console color constants
FOREGROUND_BLUE = 1
FOREGROUND_GREEN = 2
FOREGROUND_RED = 4
FOREGROUND_INTENSITY = 8 -- Foreground color is intensified.
BACKGROUND_BLUE = 16
BACKGROUND_GREEN = 32
BACKGROUND_RED = 64
BACKGROUND_INTENSITY = 128 -- Background color is intensified.
-- set colors (optional)
stdinCol = FOREGROUND_RED + FOREGROUND_GREEN + FOREGROUND_INTENSITY
stdoutCol = FOREGROUND_GREEN + FOREGROUND_INTENSITY
stderrCol = FOREGROUND_RED + FOREGROUND_INTENSITY
cx.consoleSetColors(stdinCol, stdoutCol, stderrCol)
_player.alertHook = _movie
end
----------------------------------------
--
----------------------------------------
on stopMovie
cx.consoleClose()
end
----------------------------------------
-- alertHook that prints scripting errors as stdErr to console
----------------------------------------
on alertHook (aMsg, aText, aType)
case (aType) of
#alert:
return 0
otherwise:
cx.stdOut("") -- force flush
sleep(50)
cx.stdErr(aMsg & ": " & aText & LF)
return 1
end case
end
----------------------------------------
--
----------------------------------------
on testStdOut
cx.stdOut("Hello world!" & LF)
end
----------------------------------------
--
----------------------------------------
on testStdErr
cx.stdErr("This is an error!" & LF)
end
----------------------------------------
--
----------------------------------------
on testStdIn
res = cx.stdIn("Please enter your name (+ENTER key): ")
cx.stdOut("Your name is: " & res & LF)
end
----------------------------------------
--
----------------------------------------
on testFont
cx.consoleSetFont("Consolas", 28)
end
----------------------------------------
--
----------------------------------------
on testRepl
cx.consoleSetInputCallback(#consoleInputCallback)
cx.stdOut("Type something (and hit ENTER key)." & LF)
cx.stdOut("> ")
end
----------------------------------------
--
----------------------------------------
on consoleInputCallback (str)
cx.stdOut("Your entered: " & str & LF)
cx.stdOut("> ")
end