Humanities Home page   Office of Digital Humanities
Back     BYU LiveCode Lessons Gateway

DigHT 210
Scripting Everything

In-Class Exercise: Scripting Everything

This is the exercise we will practice the concept of scripting everything by focusing on the ability to script any color setting. It is intended to be executed as much as possible by using only the message box to emphasize the point that virtually everything that can be done with the user interface can also be accomplished via scripting.

First, create a new stack and set the desired size, position on the screen, and background color:

create stack "ColorLecture"
set the width of stack "ColorLecture" to 640
set the height of stack "ColorLecture" to 480
set the resizable of stack "ColorLecture" to false
set the backgroundcolor of stack "ColorLecture" to 220,255,180

Now create a button with the indicated script:
create button "testColors"

You can open the script editor from the message box by using this command:
edit the script of button "testColors"

Type the following handler into the button's script:
on mouseUp
  answer color with the backgroundColor of this stack
  set the backgroundColor of this stack to it
end mouseUp


To test this button without clicking on it with the mouse, use:
  send "mouseUp" to btn "testColors"

(Alternatively, you can use: )
  click at the loc of btn "testColors"

Make a new card and set its background color:

create card "imageStuff"
set the backColor of this card to "180,255,220" --backColor is a synonym for backgroundColor

Import an image into the stack and place it in an image object:
create image "dog"
put url "http://chum310.byu.edu/media/images/doggie.gif" into image "dog"
Import another image:
create image "tractor"
put url "http://chum310.byu.edu/media/images/tractor.gif" into image "tractor"

set the blendLevel of image "tractor" to 50

Create a button and edit its script:
create button "Fader"
set the bottom of btn "fader" to the height of this card - 10
edit the script of button "Fader"

Type in one of the following scripts into a mouseUp handler:
(These scripts represent two ways to fade in/out a graphic image.)
--method 1: using the blendLevel property
-- fade out
repeat with i = 1 to 100
  set the blendLevel of image "tractor" to i
  wait 1
end repeat
wait 5
-- fade in
repeat with i = 100 down to 1
  set the blendLevel of image "tractor" to i
  wait 1
end repeat

-- method 2: using the visual effect command
-- fade out
lock screen
hide image "tractor"
unlock screen with visual effect dissolve
-- fade in
lock screen
show image "tractor"
unlock screen with visual effect dissolve


Back     BYU LiveCode Lessons Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University