We are in the process of migrating the Spacial Wiki content to our new Help Center at spacial.com.
Please visit the Help Center for latest Tips and Tricks, Documentation and Troubleshooting.
spacial.com/help-center

PAL Scripting 101

From SpacialAudio

Jump to: navigation, search

Link To Other PAL Articles

Table of Contents   Quick Start Guide   PAL Scripting 101   Objects   Script Examples    Music1 24 Hour PAL Script    Music 1 Hourly PAL   CBS News Scripts    Write some useful scripts


PAL 101 A starting place for all those wanting to have a better understanding of PAL and the environment and how to use it. This will be a quick Basic Programming article with more to follow .

This is a beginning for all those non programmers and a refresher for some programmers.

In PAL as any programming language there are some basics.

Data Types
Variables
Output
Condition Testing
Loops
Functions, procedures, subroutines, etc.
Abstract Data Types
OO Principles



DATA TYPES

Essential to any computer programming language. Without them, it becomes very difficult to maintain information within a computer program. Since the main principle behind computer programming is to take information, process it, and deliver the information in a different form to the user, data types obviously play a large part in determining how this is achieved.

Different languages have different constraints upon the data types that they provide.

Main variable types


Those are the majority of Data Types in PAL.

Numbers

In most languages, numbers are either integers or floating points. The number 320 is an integer, as is -125. The number 27.1 is a floating point number, as is -34.2.

The larger the range of numbers needing to be represented, the larger the (fixed) data storage requirement will be. Subsequently, and because memory and other storage has traditionally been limited, computer programming languages also provide different sizes of numbers:

Short : Small integer ranges Long : Large integer ranges Float : Small floating point ranges Double : Large floating point ranges

Strings

A sequences of characters

Where the string type is available, it should usually be an abstract data type (or class) which hides the internals from the programmer (encapsulation), and must be manipulated using the exposed functions (methods) for doing so. For example

Var S1 : String = 'This is my first string';
Var S2 : String = 'Another string';
Var I : Integer;
S2 := S1; {Copy a string}
S2 := S1 + ' and it rocks'; {Combine strings}
S2 := Copy(S1,2,3); {Copy only certain characters to a string. (Copy 3 characters, starting at position 2)

There are many String Functions available in PAL. We will discuss them in a different section.

Boolean This type is either True or False. It is a simple switch type of condition.


DateTime is a used by the date and time routines to hold date and time values.

Description

Most objects represent date and time values using the DateTime type. The integral part of a DateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed.

Following are some examples of DateTime values and their corresponding dates and times:

0 12/30/1899 12:00 am 2.75 1/1/1900 6:00 pm -1.25 12/29/1899 6:00 am 35065 1/1/1996 12:00 am To find the fractional number of days between two dates, simply subtract the two values, unless one of the DateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the DateTime value is positive. When working with negative DateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the DateTime value. For example, 6:00 am on 12/29/1899 is –1.25, not –1 + 0.25, which would be –0.75. There are no DateTime values between –1 and 0.


TDataSet (for more information on Objects TDataSet)

This object is used to access the results of a SQL query.


TStringList (for more information on Objects TStringList)

maintains a list of strings.

Use a string list object to store and manipulate a list of strings. TStringList implements the abstract properties and methods introduced by TStrings, and introduces new properties, events, and methods to

· Sort the strings in the list. · Prohibit duplicate strings in sorted lists. · Respond to changes in the contents of the list. · Control whether strings are located, sorted, and identified as duplicates in a case-sensitive or case-insensitive manner.

var List : TStringList;
List := TStringList.Create; {Create a stringlist object}
{Do stuff with object here}
List.Free; {Remember to free the object from memory once you are done with it}


TSongInfo (for more information on Objects TSongInfo)

The TSongInfo object is used to store information about a song.

Reading currently playing song information This script will read the song information of the track loaded into DeckA, and then print out the information.

var Song : TSongInfo;
Song := DeckA.GetSongInfo;
if Song = nil then
 WriteLn('No song loaded into DeckA!')
else
 begin
  WriteLn('Artist: '+Song['artist']);
  WriteLn('Title: '+Song['title']);
  WriteLn('Album: '+Song['album']);
  WriteLn('Duration: '+Song['duration']);
 end;
Song.Free;

Notice how we test if the Song = nil, because if that is the case trying to read information on the song object will cause memory access violations since the object does not exist!


TPlayer (for more information on Objects TPlayer)

TPlayer object is used to play songs inside SAM Broadcaster. Use this object to control a player.

Example

ActivePlayer.FadeToNext; {Method}
ActivePlayer.Volume := 255; {Read/Write property}
WriteLn(ActivePlayer.Duration); {Read-only property}
var Obj : TPlayer;
Obj := ActivePlayer;
Obj.FadeToNext;
//Objects support inheritance:
var Obj : TObject;
 Obj := ActivePlayer;
//if Obj is TPlayer then {Check if object is of the right type}
 TPlayer(Obj).FadeToNext; {TypeCast object to correct type and use it}
//You can also create and destroy many of your own objects:
var List : TStringList;
List := TStringList.Create; {Create a stringlist object}
// {Do stuff with object here}
List.Free; {Remember to free the object from memory once you are done with it}




variables and constants

Variables and constants are used to give a name to a certain data value. Constant values can not change during the operation of the script. Variables however can be changed at any time during the script. Unlike most languages, the name of the constant or variable is not case sensitive. Thus to PAL MyVar and MYvar is one and the same thing.

Constant values are declared as:

const MyConstValue = ConstValue;


VARIABLES

Variables provide temporary storage for information that will be needed during the lifespan of the PAL script.

Variables are also used to transfer information from one part of the script to another - for example a place to store Song information that might be needed by all parts of that script.

Imagine a variable as being a box into which information can be placed, and the type of the box (the variables type) determines what kind of information it can store.

PAL has global variables Global variables are those that are in scope for the duration of the programs execution. They can be accessed by any part of the script, and are read-write( data can be transfered to or from) for all statements that access them.

Variable Types Variables need to be defined according to their data type . Variable needs to be defined, along with its type, before use.

Examples:

var Val1 : String = 'This is a string value';
var Val2 : Integer = 1234;
var Val3 : Float = 1.234;
var Val4 : String;

As you can see, a default value is not required for variables, but it is recommended you use one where possible. The PAL language supports all major variable types like string, integer, float, boolean, variant and datetime. Variables can also be arrays and objects. Variables can get a new value during the life of a script. Let’s look at this example:

var S : Integer = 0;
PAL.Loop := True;
WriteLn(S);
S := S + 1;
WriteLn(S);
S := 123;
WriteLn(S);
PAL.WaitForTime('+00:00:10');

In the example above, the initial value of S is zero (0), and then the value is set to S + 1, which is 1+1 = 2. Finally, S is set to 123, and then we wait for 10 seconds before the script is restarted. Each time the script restarts, the variables are cleared. Thus S will have the value of 0 again once the script restarts.



Link To Other PAL Articles

Personal tools