Visviva Player | Visviva Tools | SDK for Developers | ScriptV

 

Overview Reference

  A Quick Tour

 

Now that we’ve had an abstract discussion of ScriptV Basics in Chapter 1, we’ll begin a quick tour of programming instructions for ScriptV.  Our sole aim in this chapter is to demonstrate the essential elements of the ScriptV language.  Later on, we’ll describe ScriptV in more detail.  This chapter will bring new users as quickly as possible to the point where useful programs may be written and played in the Visviva Animation Engine.

2.1.    Hello World!

Our very first ScriptV task is to print the words:

               Hello, World!

In C++ or Java, printing text is a big hurdle; to leap over it, the program text must be created and successfully compiled, loaded, and executed.  Only then will the programmer find out where his or her output went.  When using C++, creating a piece of text must be thought of as creating a piece of code.

In ScriptV, programming is straightforward.  Everything is an object; therefore, so is the Hello World text.  To write text in ScriptV, all that needs to be done is to create a label object that has the text “Hello, World!”  Using a plain text editor, type the following text:

      object hello: Label

      {

            text = "Hello, World!";

            color = white;

x = Center;

y = Center;

      }

Then save this text into a file named:

               hello.vobj

Double click the file icon.  If the Visviva Animation Engine was installed correctly, the following application window will appear at the center of the desktop:

               Hello, World!

Hit the Esc key to quit the application.

Now that a complete ScriptV program has been written and executed, it’s time for some explanations about the program itself:

A ScriptV program, whatever its size, is an object or class specification. 

A ScriptV object specification begins with the keyword object.  Following the keyword is the name of the object, then a colon, and finally a class name that specifies what kind of object it is (remember, an object is always instantiated from a class template).  The body of the object is described within a pair of curled brackets, or within the begin and end brackets, and the body contains the object’s attributes, functions, child objects, and/or the object initializer. 

In the above example, text is an object attribute defined in the class Label.  The attribute text has the type of String, and the object hello assigns the string valueHello, World!” to the text attribute.  The color attribute of the Label object specifies the color of the text, and the x and y attributes define the position of the text.  Since the “hello” object is a root object, its positional attributes are specified relative to the desktop.

2.2.    Windowing “Hello World”

The object hello cannot stand by itself: it must be contained in some place to appear.   

Every ScriptV animation title will have an outermost environment that contains it.  When the Visviva Animation Engine loads the object hello, it creates a default application environment with a plain window in the default background.  The size of the default window is exactly the size of the text appearing in the window.

Providing a new specification of a frame object can alter the appearance of the application window.  ScriptV is a hierarchical description language, so in order to add a border to the window and re-specify the size of the view, the "hello" object is simply nested in a frame object called HelloWorldApp:    

 

object HelloWorldApp:Frame

{

   width = 30mm;

   height = 8mm;

   x = Center;

   y = Center;

   border_style = Thick;

   bkg_color = white;

   object hello: Label

   {

     x = Center;

     y = Center;

     text = "Hello, World!";

   }

}

Save the above code into the file HelloWorldApp.vobj, and double click the file icon.  This will bring up the following window:

The object HelloWorldApp is a frame.  The type for this object is the class Frame.  The attributes width and height determine the size of the frame. They are specified here as 30 millimeters wide and 8 millimeters high (to use pixels or inches to define the size of objects, please see the Graphical Components reference GeoScalar for more information). The attribute border_style defined in the class Frame determines the frame border style.  border_style has multiple options.

When an object has another object nested inside it, the object is said to enclose its nested object.  In the above program code, the object hello is enclosed in the HelloWorldApp object.  The x and y coordinates for the child object hello are set to the center position of the enclosing frame.  These coordinates may also be given in inches, pixels, millimeters, or other specific positions such as Top, Left, Right, or Bottom.

2.3.    Formatting “Hello World”

The object hello is of the type Label.  Label is a pre-set class, and is defined as follows:

class Label: Drawable

{

style :           LabelStyle;

text :            String;

color :           Color;

font_name :       String;

font_style :      FontStyle;

font_weight :     FontWeight;

font_size :       FontSize;

char_set :        CharSet;

language :        Language;

deco :            TextDeco;

deco_color :      Color;

spacing :         GeoScalar;

angle :           Angle;

center :          XYScale;

info :            String;

short_cut :       Char;

}

In the Label class definition above, the x and y attributes are missing.  This is because these attributes are inherited from Label's superclass, Drawable.  Any drawable objects in the Visviva Animation Engine will have these x and y location attributes.  When the values for x and y are not given, the Animation Engine will assign default values to x and y according to the layout style of the enclosing object.

It is not necessary to assign values to every attribute of an object because all object attributes in ScriptV have default values.  The default color of the text, for instance, is the default foreground color used in the current windows system, and the default text string is the name of the object.  Therefore, label objects can be written in this simple format:

object hello: Label;

Please note that the text for the name should not contain spaces or punctuation.

There are many cases where users might want to define their own font and size to draw the text.  To do this, new values are assigned to replace the default value of each object attribute.  Consider:

object HelloWorldApp:Frame

{

   width = 30mm;

   height = 8mm;

   x = Center;

   y = Center;

   border_style = Thick;

   bkg_color = white;

   object hello: Label

   {

     x = Center;

     y = Center;

     text = "Hello, World!";

     font_size = 32;  

font_style = Italic;

font_weight = Bold;

font_name = “Times New Roman”;

   }

}

 

Whoops!  The text, as programmed, is too big to fit into the small frame!  The size of the frame may be changed by substituting larger values for the width and height attributes such as inches or pixels. Alternately, if the statements for the size settings of the window are deleted, the system will automatically figure out how big the window should be.

2.4.    Globalizing “Hello World”

Can “Hello World” be typed in English and displayed in a different language?  Yes!  The Visviva Animation Engine allows dynamic language substitutions without rewriting the script.  This can be accomplished making the text object hello be language independent.

But before we go ahead and write “Hello World” in as many languages as we can think of, let’s talk a little about the application directory settings.  A ScriptV application (or an animation title) is not a single file.  It may contain hundreds or even thousands of class files, object files, image files, sound files, language dictionaries, and various other specification files.  All of these files are organized in The Visviva Animation Engine according to a certain convention.

Most large ScriptV applications will have a number of separate file directories.  In each directory, there will be one or more object specification files with an extension “.vobj”. There will also be a number of subdirectories containing classes, images, sounds, language dictionaries, etc.

Please go to the Visviva animation Sample directory and open the HelloWorld application directory.  In this application directory is the subdirectory lang, in which the file lang.vspc is used to specify the languages supported by this application.  The file lang.vspc is written in ScriptV:

object LanguageList: Dictionary

{

      object English: LanguageSpec

      {

            font = ("Times New Roman", (), (Bold), 16,  Ansi);

            english_name = "English";

            native_name = "English";

      }

      object Spanish: LanguageSpec

      {

            font = ("Spanish New Roman", (), (Bold), 16,  Ansi);

            english_name = "Spanish";

            native_name = "Espanol";

      }

      object TChinese: LanguageSpec

      {

            font = ("MingliU", (), (Bold), 16,  ChineseBig5);

            english_name = "Traditional Chinese";

            native_name = "¤å¥ó¤å¥ó";

      }

      // ... more languages omitted here

}

Each language directory has a subdirectory that contains the translation of all language-dependent items.

For language dependent text, the application can use a language-independent text (which can be defaulted to English).  When necessary, the Visviva Animation Engine will look up the language dictionary to translate text into a language-dependent text and display the final text in the appropriate font.

Modify the HelloWorldApp.vobj file as follows:

      object HelloWorldApp: AppModel

      {

      win_style = (HasThickBorder, Center, EnableEsc);

      win_width = 200mm;

win_height = 50mm;

native_language = "Spanish";

ref_language = "English";

      object HelloWorld: Label

      {

            x = Center;

            y = Center;

            font_size = 24;   // 24 points

            font_style = Italic;

            font_weight = Bold;

            color = red;

      }

      }

The default application language has been set to Spanish.  The text used by the Label object HelloWorld is not given.  Here, the name of the object is the default language-independent text.  The Visviva Animation Engine will look up the dictionary located in the Language/Spanish directory to see whether there is an entry for the text “HelloWorld.”  Then the Animation Engine will translate "HelloWorld" into the appropriate text in traditional Spanish.  If the current operating system has a font installed that’s specified for Spanish, the Spanish characters should appear in the application window.

Now it is possible to modify the application to display the HelloWorld text in another language -- French, German, Japanese, or any other desired language.  Remember, the entry for the new language should be added to the language list and the appropriate font for the language should be specified.

The Animation Engine can load two language dictionaries simultaneously: one for a native language, and another for a reference language.  To make an application speak a new language, a user can create a new dictionary based on the dictionary of a reference language. The environment will look words up in the native language dictionary first, and then substitute the appropriate words from the dictionary in the reference language.

The benefit of this globalization mechanism is that the ScriptV code does not need to be changed in order to maintain different program versions for languages of different nations.  Both the native and the reference languages can be changed dynamically. 

Although it’s possible to use the powerful interface controls provided with the Visviva Animation Engine to design complex language configuration tools, we’ll demonstrate a simple example of a dynamic language configuration tool because this is the quick tour:

object HelloWorldApp: Frame

{

  width = 200mm;

  height = 20mm;

  bkg_color = black;

  x=Center; y = Center;

  object HelloWorld: Label

  {

     x = Center;

     y = Center;

     color = red;

     font_size = 24;

     font_weight = Bold;

  }

  object Spanish: ButtonText

  {

     y = Bottom;

     shape = Rect;

     color = yellow;

     func OnButtonActivate()

     {

       SetNativeLanguage("Spanish");

       HelloWorld.Update();

     }

  }

  object English: ButtonText

  {

     y = Bottom;

     shape = Rect;

     color = yellow;

     func OnButtonActivate()

     {

       SetNativeLanguage("English");

       HelloWorld.Update();

     }

  }

}

All we’ve done here is add two language switch buttons to the application.  The application uses English as the default language, but the native language of the application will be set to traditional Spanish and the text “Hello, World!” will be displayed in Spanish when the language switch button is triggered.

2.5.    Spinning “Hello World”

Our last stop on the quick tour is to bring HelloWorld alive with an animated display, using text with different angles.

Making the Hello World text spin is easily accomplished by inserting a key parameter animation node into the object HelloWorld:

object HelloWorldSpin: Frame

{

   width =640p; height =480p;

   bkg_color = white;

   object HelloWorld: Label

   {

      x = Center;

      y = Center;

      font_size = 24;   // 24 points

      font_style = Italic;

      font_weight = Bold;

      color = red;

 

      object rotate_animation: KPAnimation

      {  actor = HelloWorld;

         style = AutoStart;

         object key_frame: KPSection

         {  steps = 100;

            object timing: KPTiming { period = 2000;}

            object rotate_point: KPRotate

            {  axis = (0, 0, 0);

               rotate = (0,360);

            }

         }

      }

   }

}

     

The animation node rotate_animation is a key parameter animation that has 100 steps and completes one rotation in 2,000 milliseconds.  The actor of the rotation is the HelloWorld object.  The rotation animation begins after the object HelloWorld is created, as specified in the enter part of the object. 

The HelloWorld object is now ready for rotation.

 

Return to Developer's Home Page

Copyright © 2000~2005 Visviva Software, Inc. All rights reserved.