C++ we have the static variable, in Jscript we have what???

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.

C++ we have the static variable, in Jscript we have what??? // Tech Forum

1  |  

Post by ivampretti // Oct 13, 2008, 11:58am

ivampretti
Total Posts: 151
pic
so guys this is it! I love C++, and there is a statement called static that you use when declare a new variable. The static variable means that it is created only once! So when the code is executed again you can manipulate the previus value of the variable. Example of what would be in jscript:

function OnComputeOutputs(params)

{

var B=0;

while(B<=20)

{

B = Test();

}


function Test ()

{

var static A = 0;


return A++;

}

}


So with the static the sequency of returns to the A values are 1,2,3,4,...,17,18,19,20 and then stops the while loop! without the static the while loop would be infinity, because A would be 0 each time you call Test() function.


I tried to declare variables in jscript object before the function OnComputeOutputs(params) and it works! But I dont know if this is god... Maybe can bring problems in the future.


So how can I create a static variable in jscript object??

Post by Asem // Oct 13, 2008, 2:34pm

Asem
Total Posts: 255
Apparently not a quick search shoes that ecma (which I think it stands for the scripting standard). There are other ways to approach this though one would be to just use the urinary/binary node object and use it as your static variable and increment that. You can access the node through the script (purely) but it's much easier to just hook it up into the script. the node should keep track of your variable.

Post by ivampretti // Oct 13, 2008, 2:47pm

ivampretti
Total Posts: 151
pic
That looks very interesting to me Asem, how can I access a node of a variable that I created? Or I need to create urinary/binary node as a different kind of variable? I dont know anything about this...

Post by frootee // Oct 13, 2008, 5:00pm

frootee
Total Posts: 2667
pic
binary and unary nodes are available in the truespace Math-Operations library.


A connector on any node in the scene (in the Link Editor) retains its value from one call to the next. So really, if you want to use a static variable, just set the connector value on the node. It remembers the value.

Post by ivampretti // Oct 13, 2008, 6:14pm

ivampretti
Total Posts: 151
pic
Now I got what you guys are talking. Use extern objects to save the variable... With a int or number it works. But I need to save a array... the A variable was just an example to you guys understand what is the static. I would like to save a matrix, but jscript dont suport it I dont know why. And is not the matrix of position, rotation and scale that I am talking ok??:D:D


I'm developing the fluids simulator for TS in a jscript object. But I need to create a huge matrix (an array with multiple dimensions, maybe a tridimensional or more I still dont know until now, I'll have to create various arrays to support it, boring operation :mad::mad:). This matrix will be a voxel, that I need the old value to generate the new value of each element of the matrix. So any ideas?:rolleyes: please, something in the same script, nothing outside of it...:D:D

Post by transient // Oct 13, 2008, 6:44pm

transient
Total Posts: 977
pic
This sounds pretty cool.


You've proabably considered this already, but isn't the sdk c++?

Post by Asem // Oct 13, 2008, 7:25pm

Asem
Total Posts: 255
You may have to take a look at the sdk. There was talk about ts supporting python like it did before but here's would be my approach. unfortunately I would still need a 2nd jscript node object to be my static keeping thing but at least I should be able to use multi-dimensional arrays.

The idea is to have one jScript object have the sole purpose of being static or in this case storing values. Creating an empty array that should be able to match most arrays that I intend to use like.


jscript 1:

//Sorry haven't missed with jscript much so I'm going to make it look like c++

type array[][][];

this should be able store a 3d matrix of any size for me.

the second jscript -> jscript 2:

m_arr[][][]... do calculations

LE.somehting(where jscript 1 is, array[][][]) = m_arr[][][];

do other m_arr[][][] calculations

grab previous results

m_arr2[][][] = LE.somehting(where jscript 1 is, array[][][])

hope that made sense lol. also I don't remeber the exact system thing to grab var from another node but I've done it before. The biggest problem I ran into was the fact that I had to write the path a lot. I probably should of created some global strings but I didn't last time.

and so on......


This isn't pretty but in general it would do what you want. The funny thing is I did a little searching about statics in scripting and they all have that problem. The idea I gave is kinda based on pythons generator thing.


python example:


def static_num2():
k = 0
while True:
k += 1
yield k

static = static_num2().next

for i in range(0,10) :
print static()There's more since this was from a discussion: here (http://www.daniweb.com/forums/thread33025.html)
ignore those numbers on the left side.



Python seems to be the closest to this result. I might be a good idea for caligari to bring in python at some point.

If this ends up being a pain because it kinda does. I would use the sdk but honestly that looks like a pain lol.

Also frootree you're working on bringing in the fluids from blender right? I had thought of the same thing because I saw a 3ds max script that did the same thing. It might be good reference.

ivampretti, I would look into using the sdk if your doing this from scratch as when you can get the basic startup down you would be able to focus on the voxel math stuff. The script can do this but I guess either way it wil be a good amount of work.

Post by Asem // Oct 13, 2008, 7:37pm

Asem
Total Posts: 255
There also seems to be away around this by creating static yourself but it may be no diffeent than what I showed. (I could be completely wrong about that though since I didn't really want to follow the code I saw).

Post by frootee // Oct 14, 2008, 2:24am

frootee
Total Posts: 2667
pic
you can add an attribute (input connector basically) to a node which contains:


Universal Array Data

Int Array Data

Number Array Data

String Array Data

Boolean Array Data


these are part of the Common Data Package/ set.


How to do:


add jscript node.


click orange square


select Attributes tab


select: Add attr


click dropdown arrow for Type.


Scroll through the list. You will find the Common Data Package set.


jscript connectors retain value from call to call. They are static.


Getting started in scripting and LE, get powerpoint presentation here:


http://truesourceshop.com/agoracart55/agora.cgi?cart_id=1343661.11217&p_id=00015&product=Tutorials&xm=on&ppinc=search2
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