Virtools VSL

Recently I was asked how to use global variables inside global functions using VSL, one of 3DVIA Virtools built-in scripting languages.

In VSL you can share a variable across diferent "Run VSL" BuildingBlocks by using the keyword "shared". For example

Besides using VSL in BBs or actionscripts, you can also create "global" VSL scripts. These are automatically included. The things is that you can not use the shared keyword inside global scripts. So if you want to modify shared variables inside global functions, one workaround is to use parameter-objects.

Basically it's a struct containing variables you like to share. Either one struct for all or split your variables by context into different structs. This user defined structure makes passing them to functions much easier. Also less code changes are required when adding more data.

Above you see the definition and how it's used as input parameter of a global function. This works because it's passed by reference and not as value (/copy). This way you can modify shared variables even inside global functions. Here is how it could look like inside a VSL BB that calls the global function:

I hope this will help a few more people. If it's not clear, let me know.

I finally uploaded the DLL with *some* bindings regarding CKObjectAnimation and CKKeyedAnimation. The DLL is probally compatible with 4.0 as, so far as I could see in the beta, it's still not bound by default. I don't know why as it's really not much work.

I prefixed the classes with CK like it's done in the SDK for that there ain't any conflicts when Virtools does these bindings finally, too. Then just delete the DLL and see which scripts do not compile anymore and adjust them.


(Cast, Get3dEntity, Set3dEntity, Shared, CreateMergedAnimation, GetMergeFactor, IsMerged, GetCurrentStep, GetLength, SetMergeFactor, SetLength, SetStep, HasMorphInfo)


(Cast, GetAnimationCount, Clear, GetAnimation, RemoveAnimation, AddAnimation)

Getting a list of all portals is a bit more complicated than one might think at first as it's not a class. A portal is a 3D Entity with special flags. So here is the Run VSL code. Note that scene is a pIn of type Scene and portals is a pOut of type ObjectArray. I am also using feranti's for-loop style


void main()
    ObjectArray ents;
    bc.FillObjectArrayByType(ents, CKCID_3DENTITY, false, scene);
    int count = ents.Size();
    Entity3D ent = NULL;
    for(int i=-1; ++i<count;)
        ent = Entity3D.Cast(ents[i]);
        if( and(ent.GetFlags(), CK_3DENTITY_PORTAL) )

Just a little hint: the XStringTokenizer class is also available in VSL. It's really useful.

// VSL BB code
void main()
    // normally fill that via pIns
    String text = "hallo#this#is#a#tokenizer#test#endOfMessage";    
    String delimiter = "#";

    // the tokenizer stuff
    StringTokenizer tokenizer(text.Str(), delimiter.Str());
    str token = NULL;
    while( (token= tokenizer.NextToken(token)) != NULL )