// Henjin Text Demo
// (c) 2008, Notequalsoft Games
// http://www.notequalsoft.com/games/henjin/
// This demo demonstrates several functions that can be performed on text.
// setup system
System.Size 640 480
System.Continue true
System.CreateTextBox TextBox 0 0 640 480
TextBox.DisplayAtOnce true
System.CreateImage WaitImage 619 460 18 17 "waiting.gif"
System.WaitImage WaitImage
label START
// display some embedded HTML in a TextBox
TextBox.Text "Look, Ma! I can be bold, italicized, underlined, or all of them at the same time!"
react
// multiple lines of text in a TextBox with line breaks (\n) between each
TextBox.Text "first line\n"
TextBox.AddText "second line\n"
TextBox.AddText 'third line\n' // note that single quotes are fine, too
TextBox.AddText "fourth line"
react
// display the value of a string variable
set message = "Hello World"
TextBox.Text message
react
// display the value of a numeric variable
set pi = 3.14159
TextBox.Text pi
react
// display numerous variable values embedded in other text
TextBox.Text "The message I want to say is {message}!\n \nThe value of pi is approximately {pi}."
react
// does the pi variable contain a number?
setisinteger piisinteger pi
setisfloat piisfloat pi
TextBox.Text "Pi is an integer? {piisinteger}\nPi is a floating-point value? {piisfloat}"
react
// perform some simple string modification
setleft hello message 5 // "Hello"
setright world message 5 // "World"
setsubstring or message 7 2 // "or", note that the first character is index zero
setlower lower message // "hello world"
setupper upper message // "HELLO WORLD"
TextBox.Text "Is it {message}, {lower}, {upper}, {or} {world} {hello}?"
react
// you can concatenate a string to do the same thing
set newmessage = "Say {hello} to the {world}."
TextBox.Text newmessage
react
// perform some regular expressions string variables
settest messagehasspaces message "\s"
settest messagehasnumbers message "\d"
set phonenumber = "1-800-555-1234"
settest phoneisvalid phonenumber "\d\-\d{3}\-\d{3}\-\d{4}"
TextBox.Text "'{message}' contains spaces? {messagehasspaces}\n'{message}' contains numeric digits? {messagehasnumbers}\n'{phonenumber}' is valid? {phoneisvalid}"
react
// show the difference in the DisplayAtOnce value
TextBox.DisplayAtOnce false
TextBox.Text "This will display one character at a time."
react
TextBox.DisplayAtOnce true
TextBox.Text "This will display all at once."
react
// override a false value for DisplayAtOnce with the flush attribute for an embedded HTML span
TextBox.DisplayAtOnce false
TextBox.Text 'This will display one character at a time, except this part which displayed all at once.'
react
// specify options in the TextBox with the onclickgoto attribute for an embedded HTML span
// setting System.Continue to false is useful to disable advancement by clicking or keypressing, in effect forcing selection of one of the options
System.Continue false
TextBox.DisplayAtOnce true
TextBox.Text 'Click here for option 1\nClick here for option 2'
react
label OPTION1
System.Continue true
TextBox.Text "Option 1 clicked"
react
goto CONTINUE
label OPTION2
System.Continue true
TextBox.Text "Option 2 clicked"
react
goto CONTINUE
// clear display
label CONTINUE
TextBox.Clear
react
// repeat demo
goto START