JScript and passing arrays

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.

JScript and passing arrays // Archive: Tech Forum

1  |  

Post by ProfessorKhaos // Sep 30, 2006, 6:01pm

ProfessorKhaos
Total Posts: 622
pic
Hi all,


Ya'll have been very helpful so far (thanks Norm!) but I've got another puzzler that I can't figure out. Seems like I should be able to do it but maybe not.


I have a JScript Control who's only job is to load a text file into an array and make this array available as an output. Each element in the array contains a line from the file.


Depending on how I want to process the lines, some items will be interpolated directly but some require the ability to wrap angles above and below 360 degrees PRIOR to interpolation. No biggie there either.


What I'd like to do is something like the following


File ->GetFileData -> Array


Array & Time -> GetRelevantLines -> 2 strings containing lines of interest (before and after supplied time)


2 strings + collum withing strings + interpolation method -> interpolaterScript -> interpolated and/or wrapped data


I'm trying to get the array recognized into the GetRelevantLines control but it can't seem to recognize the incoming data as an array.


Test code for reading array passed as a param is roughly as follows:


function Execute(params)

{


DataArray = params.conValue('DataArray');

Time_In = params.conValue('Time In');


// TODO: put your action code here


count = DataArray.length;


params.ConValue("DataString1") = DataArray[0];

params.ConValue("DataString2") = DataArray[1];

params.ConValue("Time Out") = Time_In;

}


Can't seem to get past the count = DataArray.length statement.


The routine that reads files and feeds array data to the above script via Rosetta link doesn't seem to complain at all (this is 'GetFileData').


function Execute(params)

{


// TODO: put your action code here


strFilename = params.conValue('Filename');

rline = new Array();


fs = new ActiveXObject("Scripting.FileSystemObject");


// does file exist?


if (fs.FileExists(strFilename))

{


// load file into array


f = fs.GetFile(strFilename);

connToFile = f.OpenAsTextStream(1, 0);

var count = 0;

while( !connToFile.AtEndOfStream )

{

rline[count] = connToFile.ReadLine();

count++;

}

connToFile.Close();

}


params.ConValue('DataArray') = rline;


}


the 'DataArray' attributes on both objects are defined appropriately as 'array' with respective IN and OUT settings.


I can build everything I need into a single file reading script (and in fact have) but for modularity I thought it might be helpful to create several scripts that could be linked visually with Rosetta to avoid recoding.


Could it be that the array is destroyed upon exit from the 'GetFileData' control and the 'array' parameter passed as output is really just a pointer that becomes irrelevant after the call? Seems weird if it's true but then I've seen weird code issues before.

Post by Norm // Sep 30, 2006, 6:14pm

Norm
Total Posts: 862
pic
I will be honest and say you can not do it in current version.

I am however testing that exact scenario with ts7.5. We have ability to pass an array to output or take it in through input connectors. What is even better is if you like, you can go wireless again and call the array's elements by referencing that output connector.


So don't fret over it. As I provided the method to access text file, you can use it in your script. Your scripts have to be "self-sufficient" at current ts7.11 version.

Post by ProfessorKhaos // Sep 30, 2006, 7:10pm

ProfessorKhaos
Total Posts: 622
pic
Thanks Norm! Was curious about that. It's more of a style question than a limitation at this point. I am able to accomplish significantly more this afternoon than yesterday using your examples. Just looking at how much reusable code I can throw in my toolbox for later. For now I'll just combine the GetFileData and GetRelevantLines scripts into one since I know I can pass strings down the line easily enough. From there it still gives me some very good flexibility as to how I want to handle the data (i.e. selection of collumns within strings, angle wrapping/interpolation method, etc.)


Though it's not a requirement for my current project, I stress tested my all-in-one file reader/value interpolater and got surprisingly good performance. I used a 10000 line file created with excel. It was tab delimitted and contained a time field and a value field (basically sin(time))


The screen update rate was still fairly good considering my all-in-one method loads the data on each and every control pulse. Been browsing through your other thread to see how to do it without reloading every time (still some work to go though...)


Thanks again for your help!


N.F.

Post by Norm // Oct 2, 2006, 5:18am

Norm
Total Posts: 862
pic
Scripts run very fast on their own in trueSpace. Where the cpu hit come into play is when you introduce geometry into sceneario. Once you do this, you see performance hit take place.


I too was surprised to see how fast scripts run.
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn