Xbase 1.0.4 Released

Xbase 1.0.4 is out. Almost all of the changes to 1.0.4 are to do with the scripting APIs. They’ve been reorganised, improved and lots of new features have been added.

Documentation for everything you see below is available here:

Tools

The Tools class has been completely restructured (full backwards-compatibility has been retained, however).

Tools.Beep()

Tools.Beep() may now take an optional argument: the name of the beep sound you want to play.

//A normal beep
Tools.Beep();

//Play the "Submarine" sound
Tools.Beep("Submarine");

//Play the "Bottle" sound
Tools.Beep("Bottle");

Tools.TextAlert()

Tools.TextAlert() is a new function that acts rather like the prompt() function in regular javascript.

var result = Tools.TextAlert("Please enter some text...", "", "I'm done.");

Log("You pressed the button called " + result.button);
Log("You typed in the text field: " + result.text);

Alert class

The new Alert class gives you greater control over. It may also be expanded in the future to give you greater control over alerts.

var a = new Alert;
a.title = "This is an alert!";
a.message = "Hello James! This is an alert showcasing the new Alert class.";
a.mainButton = "My name isn't James";
a.secondaryButton = "How did you know my name?";

a.show();
Log("You pressed this button " + result.selectedButton);

Tools.ChoiceAlert() ➞ Tools.Alert()

Tools.ChoiceAlert() is depreciated in favour of Tools.Alert(). Tools.Alert() now has the full functionality of ChoiceAlert() but retains backwards compatibility.

The following are depreciated:

  • Tools.ChoiceAlert.Default
  • Tools.ChoiceAlert.Secondary
  • Tools.ChoiceAlert.Third
  • Tools.ChoiceAlert.Error

The intended replacements are:

  • Alert.MainButton
  • Alert.SecondaryButton
  • Alert.OtherButton
  • Alert.ErrorResult.

For example:

var button = Tools.Alert("Are you sure you want to do that?", "Doing that might do something bad, make sure you've saved before doing it.", "Do it", "Don't do it","I like turtles");

if (button == Alert.MainButton)
    Log("You clicked the main button!");
else
    Log("You clicked another button!");

Log

1.0.4 introduces a new class, Log

The following are depreciated:

  • Tools.Log()
  • Tools.Print()

The intended replacements are:

  • Log()
  • Log.Print()

The following functions are new:

  • Log.PrintError()
  • Log.Clear()
  • Log.ClearAll()
  • Log.Text
  • Log.Contents

For example:

Log("This is a debugging message");

Print("This prints text to the console");

PrintError("This prints an error. Errors have purple backgrounds and are easily distinguishable.");

//This will return the text of the console (as a string)
var text = Log.Text;

//This will return the contents of the console (as an array of strings, one string for each session)
var contents = Log.Contents;

//This will clear everything outputted to the console this session
Log.Clear();

//This will clear every session from the console
Log.ClearAll();

Form

Accessing Controls

You can now access controls like this:
Form[controlName]

For example:

//Old way (still valid - not depreciated)
var c1 = Form.ControlNamed("Celsius");

//New way
var c2 = Form["Celsius"];

Frames, Visibility and Animation

The frames of controls (position and size) can now be changed. As before, the visbility of a control can be changed too. These changes can also be animated with animators

//Set the frame of a control
var newFrame = Form["myButton"].frame;
newFrame.size = 100;
Form["myButton"].frame = newFrame;

//Changes can also be animated
newFrame.x = 10;
Form["myButton"].animator.frame = newFrame;

//Controls can be hidden and show using the visibility property of the animator
Form["myButton"].animator.visible = false; //Hide

Methods ➞ Properties

The following methods are depreciated:

  • Form.GetGlobal(key)
  • Form.SetGlobal(key, value)
  • Form.Rowid()
  • Form.LastEditedField()
  • Form.ContentTable()
  • Form.ControlNames()
  • Form.Name()

The intended replacements are:

  • Form.getGlobal(key)
  • Form.setGlobal(key, value)
  • Form.rowid
  • Form.lastEditedField
  • Form.contentTable
  • Form.controlNames
  • Form.name

The following properties are new:

  • Form.width
  • Form.height

Data

As with everything else, the Data class has been rearranged and made easier to use.

Table Class

You can now access tables directly using the new Tables class:

var aTable = Data["Products"];
var numberOfRows = aTable.numRows;

//Or
var bTable = new Table("Products");
numberOfRows = bTable.numRows;

Log(numberOfRows);

Fields

There’s also a new Field class:

var name = Data["Products"]["Name"];
var firstName = name.value(0);

name = new Field("Products", "Name");
name.setValue(0, "iPod");
Log(firstName);

Misc

Tools.StopScript()

The Tools.StopScript() function halts execution of the script. Take care when using this function.

Document.Shake()

The Document.Shake() function shakes the window from left to right (emphesises that incorrect data has been entered). Use sparingly!

Document.MarkAsNeedingChanges()

The Document.MarkAsNeedingChanges() marks the window’s close button with a dot. When the window is closed or Xbase quit, the user will be prompted to save changes.

Leave a Reply