Question about "var" type

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Question about "var" type // New Users

1  |  

Post by PrimMac // Mar 8, 2006, 5:51am

PrimMac
Total Posts: 78
Hello everyone,


I was trying to see what the Shift command (of the "Math Package\Matrix Float Data" object type). It asks for a "var" type argument. I assumed it was a number so I passed 20 as the value, but I got a type mismatch error. Does anyone know what "var" types are supposed to be? They are used by many of these functions. Thanks.

Post by Norm // Mar 8, 2006, 7:28am

Norm
Total Posts: 862
pic
If you drag a new jscript object into the le and enter it, you can see straight away the Attributes tab. You Add new attribute and you will be able to access a dropdown list of "types" of input/output connectors.


There is quite a list of types to be sure. When you realize this you can scroll down the list and see there are types like: MathPackage/Matrix Float Data. So here is where I would go with it, as method to gain a little knowledge as to what is happening.


I create two attributes in my new jscript object:


MathPacMatrixFloatDataIn

MathPacMatrixFloatDataOut



I set each new attribute to type MathPackage/Matrix Float Data. When these two attributes are created, you exit the Attributes tab and go to Methods tab. Image attached shows what you find when you get there.


function OnComputeOutputs(params)

{

MathPacMatrixFloatDataIn = params.conValue('MathPacMatrixFloatDataIn');


// TODO: put your computation here

// MathPacMatrixFloatDataOut = System.CreateDO('Math Package/Matrix Float Data');


// params.conValue("MathPacMatrixFloatDataOut") = MathPacMatrixFloatDataOut

}


This tells us quite a bit really. There is info on how to create a new Matrix Float package (if required .. note it is commented out). It also has set up ability to pass a value and export again, if required.


I code nothing yet, I exit the Script Editor and am back in the LE. I create a simple cube in Model view and note it appears as a node in the LE. I expand the Cube node to see what it has for exported attributes. It has Matrix attributes ... which to me is what we look for here. I can expand the ObjMatrix attribute and see what makes up the matrix data. I can try to connect the ObjMatrix output from the Cube and it takes on my jscript input connector for MathPackage/Matrix Float Data!


From the expanded matrix of cube, I see some of what you are asking about. The matrix of the cube is made up of more than a single number, it has all the translation, rotation, scale and shear data values. So to make simple, is an array of data. Trying to send in single value of 20, throws the error. It is expecting an array. I attach second image showing this scenario in LE.


My next step in the exploration of this scenario is to enter the jscript object again and set up the script with simple transfer of data from the input connector to the output connector like this:


function OnComputeOutputs(params)

{

MathPacMatrixFloatDataIn = params.conValue('MathPacMatrixFloatDataIn');


// TODO: put your computation here

// MathPacMatrixFloatDataOut = System.CreateDO('Math Package/Matrix Float Data');


params.conValue("MathPacMatrixFloatDataOut") = MathPacMatrixFloatDataIn;

}


Now when I return to the LE, I can right-click the output attribute for my jscript object and "expand" it like I did to the Cube's ObjMatrix output connector. I can see all the values in this newly expanded connector, mirroring the values from the Cube's expanded matrix. This is success right?


Next step to take in the process is to find object that uses and breaks down this information somehow. How is it used?


I was asking same questions long ago, so I ended up creating the MatrixInfo object you will find in Library: Objects/Script Objects/Matrix Info.

Last image I attach shows you how I hooked it up and how you see all the info accessed on panel/interface of Matrix Info script object.


If you enter the Matrix Info/jsMatrix script object, you can see how I called each attribute and transfered info.


Hope is helpful. If I run into something I am not familiar with, I will sort of use the same process to experiment and try to get info on what is happening. There is a bit of trial and error, but such is the life of a pioneer :)

Post by trueBlue // Mar 8, 2006, 8:08am

trueBlue
Total Posts: 1761
pic
Arguments

variable1, variable2 The names of the variables being declared.
value1, value2 The initial value assigned to the variable.
Remarks

Use the var statement to declare variables. These variables can be assigned values at declaration or later in your script.

Example

The following example illustrates the use of the var statement.
var index;var name = "Thomas Jefferson";var answer = 42, counter, numpages = 10;

Post by PrimMac // Mar 9, 2006, 2:32am

PrimMac
Total Posts: 78
Thanks for that detailed answer Norm (thanks to you too trueblue).


I was wondering how to transfer input values into output values. I also did not know about the Expand option for attributes. This will certainly be a great help in deciphering what the different commands are for. I used the MatrixInfo object a while back, very interesting. In fact, I made my own "Light Matrix Info", which was similar, but only showed the X, Y and Z location values :)


Thanks to you as well, trueblue. I had forgotten that in jScript the var command is used to declare variables. But that is not exactly the "var" I meant.


Here is the "var" I mean: When I drag a new vbScript object into the LE and decalre a Math Data Package\Matrix Float Data attribute and go to the code, it looks like Norm said:


' OnComputeOutputs

' Called to compute values of all output connectors

Sub OnComputeOutputs(params)

Set inM = params.conValue("inM")


' TODO: put your computation here


' Set outM = System.CreateDO("Math Package/Matrix Float Data")


' params.conValue("outM") = outM

End Sub


Notice that my attributes are named inM and outM ("in Matrix" and "out Matrix"). I personally am a fan of short names. Anyway, say that I write "inM." here inside this code. A combo box appears with many functions for the Matrix Float data attribute. Some of these are "AddScaleShear(real,real,real,real,real,real)" and "Compose(var)". Those are the first two on the list, but there are many others.


For the AddScaleShear command, I assume it takes six real (floating point) numbers. Others commands take "uint" parameters. I assume this means "unsigned integer". But notice that "Compose(var)" command. What can I assume a "var" argument is? "Var" obviously stands for "variable" or "variant". Is it perhaps an array with the whole matrix float data in it? The Shift command also accepts a "var" type command, which is the one I was trying to figure out what it does.


I will continue to experiment with this, using the Expand technique Norm just tuaght me :) to explore other areas.


Many thanks again for both your answers.

Post by PrimMac // Mar 10, 2006, 8:28am

PrimMac
Total Posts: 78
I have been checking the Manual and the Developer's Guide in search of how to use these functions such as AddScaleShear, Compose or Shift, but I can't find anything on them. It seems they were not documented.


I guess I will have to forget all about programming trueSpace, and just use the same features I already know from 6.6., as there is apparently no reference guide for these commands. Simply guessing what the commands do isn't doing anything for me either. Those I have been able to get to actually connect without getting vbScript errors, don't seem to do anything (or perhaps something else must be done, but I don't know what).

Post by peterma // Mar 12, 2006, 11:10pm

peterma
Total Posts: 48
Hello everyone,


I was trying to see what the Shift command (of the "Math Package\Matrix Float Data" object type). It asks for a "var" type argument. I assumed it was a number so I passed 20 as the value, but I got a type mismatch error. Does anyone know what "var" types are supposed to be? They are used by many of these functions. Thanks.


As for the "var" type arguments (as displayed in Code Completion popup), there are 2 possibilities in generak:


- it is a data type (e.g. "Math Package/Point Data" as a parameter for the Shift method in Matrix data type)

- it is some low-level c++ data type not accessible from scripts (e.g. general pointer, complex structure etc)



So sometimes you cannot use particular method from script, but the big advantage is that these methods are common for script and for native tS code so the 3rd party script writer can use the same interface like internal tS developer. (unlike in tS6.6 and prior). As a convequence, you can use new methods / data objects right after they are added to the system.


What is strange I see these methods (Shift, Compose, ...) documented well in our code / xml doc, so I don't know why you cannot find it in developer's doc. You found no line about the 'Shift' method in particular ?

Post by PrimMac // Mar 13, 2006, 4:53am

PrimMac
Total Posts: 78
You're right peterma,


I hadn't looked thoroughly enough in the additional folders that come with the PDF Developer's Guide. I mean, I had looked at these files, but the names are a bit different from TS, so I assumed it meant names of classes used in C++, not in TS vbScript.


Inside TS, this type is called "Math Package\Matrix Float Data" but in the docs, it's called IRdMatrixfDisp. This should get me started on TS scripting, I hope. :). The reference IS there, one just has to know where to look. Thanks for pointing me in the right direction.
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn