Difference between revisions of "AlcScript Technical Information"

(Object Script)
 
Line 70: Line 70:
  
 
In this case, it returns "fixed" if the key was not in alcscript, but else, it returns whatever value was specified...
 
In this case, it returns "fixed" if the key was not in alcscript, but else, it returns whatever value was specified...
 +
 +
[[Category:AlcScript]]

Latest revision as of 05:12, 14 April 2011

AlcScript

AlScript is a hierarchical, human readable script, basically just a YAML implementation.

It is stored in the Blender text file "AlcScript" - but this may change to "ObjScript", to perhaps reflect different files, one for blender objects ("ObjScript"), and one for generic age settings and to replace the Book/Page objects ("BookScript").

YAML is based on different indentation levels.

Object Script

Basically, the first indentation level should contain object names, and each further indentation level, a different class of settings. All key names should be lowercase!

Example (Note - this is fictional AlcScript code):

island:
    visual:
        sprite: true
    physical:
        friction: 5.0
        elasticity: 3.0
    logic:
        type: clickable
        python:
            file: filename.py
            arguments:
                - type: int
                  value: 0.0
                - type: str
                  value: Access
                
camera1:
    brain:
        type: avatar
        poa: 0,0,0
        offset: 0,0,6

As you see, each key/subkey can either contain a further indentation level, or a value. The "-" character indicates a new list item.

The alcscript object

In alc_AlcScript.py there is defined the AlcScript class. The object loads in an alcscript YAML text, and converts it into a list or dictionary that contains dictionaries or lists containing the subkeys or sublists. This list or array is stored in the object.

The object also defines the .Find(key) and .FindOrCreate(key) functions, which locate a root object in either the list or array, to obtain a dictionary that corresponds to the object's name (the 'key').

.Find(key) 

returns an empty dict if the keyt is not found. (Used on exports)

.FindOrCreate(key) 

creates a new entry in the object dictionary, and returns that object. (used on imports).


Static properties

The AlcScript object has static functions that read in the files, and are called on start of export.

It also contains the static variable "objects", which is an AlcScript object, that has the list of object-related AlcScript items.

So, to get the alcscript related to an object, one should do:

objscript = AlcScript.objects.Find(obj.name)

It returns a dictionary object that contains the parsed alcscript data

Reading in object properties

After obtaining the dictionary, getting a sub-sub-subkey out of it could require a lot of code, and if statements.

To avoid that, the alc_AlcScript.py file also defines the function:

FindInDict(dict,key,default=None)

It locates the subkey in your dictionary (use "." to separate it), and returns the default value that you specify (or None if it is not found

So, in order to get the value of [object].camera.brain.type, one should do:

objscript = AlcScript.objects.Find(obj.name)
camtype = FindInDict(objscript,"camera.brain.type","fixed"

In this case, it returns "fixed" if the key was not in alcscript, but else, it returns whatever value was specified...