Calculation Node problem

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.

Calculation Node problem // Interactive Artwork

1  |  

Post by bill // Aug 20, 2006, 4:45pm

bill
Total Posts: 114
pic
I'm having difficulty setting up this caluclation node to be used to calculate an angle. I keep getting the following error. Does anyone know what I'm doing wrong?

Post by Norm // Aug 21, 2006, 6:36am

Norm
Total Posts: 862
pic
I copy and paste code from your script here bill:


function OnComputeOutputs(params)

{

input = params.ConValue('tz_in');

input = params.ConValue('tz1_in');

input = params.ConValue('tx1_in');

params.ConValue("link_angle") = rxt_Atan2('tx1_in',('tz_in'-'tz1_in'));

}


I highlighted in red, problems I see.


Solution:

When you create a connector via attributes tab of script, the scripting engine will provide automatic population of the code to identify your attributes. It should look like this after inputting the three input attributes you created:


// Execute

// Called to execute the command

function Execute(params)

{

tz_in = params.conValue('tz_in');

tz1_in = params.conValue('tz1_in');

tx1_in = params.conValue('tx1_in');


// TODO: put your action code here


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

}



The above code is what you get by default when you switch to the Methods tab of script. So in essence, you populate variables tz_in, tz1_in and tx1_in, with input connector values. trueSpace creates this for you so once you are finished creating attributes, you are able to easily use the values in your script.


That being said, the algorhythm used is not something that jscript understands. You can google "Math.atan2" and find pages that go over all the "Math.xxx) items available. I believe you are on right track, just try making the code for algo to look like:


aValue = Math.atan2(tx1_in,(tz_in - tz1_in));


aValue is a new variable I added to hold the value of the algo. Next, have to populate the output parameter you created (and trueSpace partially builds for you):


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



to:


params.ConValue("link_angle") = aValue;


This should leave you with end code looking similar to:

// Execute

// Called to execute the command

function Execute(params)

{

tz_in = params.conValue('tz_in');

tz1_in = params.conValue('tz1_in');

tx1_in = params.conValue('tx1_in');


// TODO: put your action code here

aValue = Math.atan2(tx1_in,(tz_in - tz1_in));

params.ConValue("link_angle") = aValue;

}


Seems to work ok here with the new code bill.

Hope is helpful.

Post by bill // Aug 21, 2006, 7:56am

bill
Total Posts: 114
pic
Thanks Norm. I'm not a programmer, although I can follow programming logic, so I'm struggling to figure out how to do all this. I know what I want to accomplish. Just not how to program it all. I understand now what I did wrong. Thanks again.

Post by bill // Aug 21, 2006, 9:17am

bill
Total Posts: 114
pic
Norm, I tried your code but it does not appear to work. I am no longer getting the errors but the result of the calculation is always 0 no matter what numbers are entered into the inputs. Any other suggestions? Perhaps aValue needs to somehow be defined as a variable?

Post by RichLevy // Aug 21, 2006, 11:00am

RichLevy
Total Posts: 1140
pic
Norm


Is there a definitive programming reference we can look into to find out more about programming Jscript and the TS LE? I have the developers guide, and the Artists guide, but they seem to be lacking of info for us nonprogrammers (I fit squarely in the hacker category... meaning I hack my way thru code)


Rich

Post by bill // Aug 21, 2006, 12:37pm

bill
Total Posts: 114
pic
Ok, never mind. I got it. This is the final code and I think it does what I wanted. I added a little more to it to convert the result to degrees. Thanks again for your help.

// OnComputeOutputs
// Called to compute values of all output connectors
function OnComputeOutputs(params)
{
tz_in = params.conValue('tz_in');
tz1_in = params.conValue('tz1_in');
tx1_in = params.conValue('tx1_in');


aValue = Math.atan2(tx1_in,(tz_in - tz1_in)) * (180 / Math.PI);
params.conValue("link_angle") = aValue;
}

Post by stan // Aug 21, 2006, 12:46pm

stan
Total Posts: 1240
pic
here is the download link for the help file for jscript 5.6

http://www.microsoft.com/downloads/details.aspx?FamilyID=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en&Hash=W7YJ6M8

Post by Alien // Aug 21, 2006, 12:47pm

Alien
Total Posts: 1231
pic
Is there a definitive programming reference we can look into to find out more about programming Jscript and the TS LE? I have the developers guide, and the Artists guide, but they seem to be lacking of info for us nonprogrammers (I fit squarely in the hacker category... meaning I hack my way thru code)

Do you have Windows Scripting Host (http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=C717D943-7E4B-4622-86EB-95A22B832CAA)? If so, look in the help file that came with it, as it not only covers WSH, but also VB & JS as well. Unfortunately you can only now get it if you have Windows Genuine Annoyance installed, so I must have got it before they started using that. [I get my updates from Windizupdate (http://www.windizupdate.com) - they're still directly from MS, you just don't need WGA to get them, but they only provide updates, not WSH]

Post by Norm // Aug 22, 2006, 7:15am

Norm
Total Posts: 862
pic
Alien is correct, the online documentation for vb script and jscript is where I pretty much found my information. This may not address scripting in trueSpace for non-programmers but it will serve as good reference.


Hopefully a basic scripting course will appear on horizon.
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