script function sets :)

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.

script function sets :) // Scriptorium

1  |  

Post by Norm // Aug 30, 2007, 5:40am

Norm
Total Posts: 862
pic
Anyone had a chance to check out function sets yet? :D
Peter Makcovsky created this small demo some time back: Feb/2007.

Post by Norm // Aug 30, 2007, 5:50am

Norm
Total Posts: 862
pic
Here is some conversation that accompanied the scenario between Peter and myself:

Peter:
Script function sets are new (advanced) type of scripts, introduced in ts7.5

- load the attached scene
- execute 'PrimeCheck' command with different 'a' values
- execute 'Factorial' command with different 'a' values
- explore the scripts inside

ExtMath, where the actual computation is done, is an example of script function set.
Unlike script commands or objects, function sets cannot contain any connectors, and cannot be 'executed' directly - so in LE they appear lifeless. Only when accessed from script command, they can reveal their power.

Here are some benefits:

- if fn set is included in the project (scene), all commands in the project can access it easily (see both commands in the demo)
- fn set can contain set of function or variables, logicaly grouped into one container (e.g. extended math fn set, matrix aritmetics fn set, scene traversing fn set etc)
- fn set can contain shared piece of code that is used frequently in the project

Norm:
Interesting Peter. Are there any predefined keywords or such that we should know about for this? I noted "factorial" keyword used and wondered if it was documented or if any others existed we could try out.

Peter:
Norm when you look into the 'Factorial' command, there are 2 interesting lines

fn = Node.AccessNearFnSet("ExtMath");

fact = fn.Factorial( a );

- first one access the function set "ExtMath"
- second one perform call to the function set (i.e. calls user-defined Factorial function defined in the function set)


when you navigate to second line and type point '.' after the 'fn', the code completion popup appers with list of all functions defined in the fn set "ExtMath"


Now you can go to the "ExtMath" fn set and append your own function there - e.g. empty function Test.
After returning to the Factorial command, you should see your function name in the code completion popup, next to 'Factorial' and 'isPrime'

Norm:
hmmm, interesting Peter.
Can we stack functions in one node and call them with something like:

fn = Node.AccessNearFnSet("ExtMath.normsCustomFunction");

Peter:
You can pack the function call into one line:

result = Node.AccessNearFnSet("ExtMath").NormsFunction( a );




Instead of 2 lines

fn = Node.AccessNearFnSet("ExtMath");

result = fn.NormsFunction( a );



Drawback is that Code Completion does not offer list of available function for '1 line call version' as you type

Post by Jack Edwards // Aug 30, 2007, 7:25am

Jack Edwards
Total Posts: 4062
pic
I'll definitely be able to make use of this in my current scripting project. Thanks Norm. :)


Say you wouldn't happen to have that scene traversing one handy would ya? ;)


-Jack.

Post by frootee // Aug 30, 2007, 7:54am

frootee
Total Posts: 2667
pic
thanks Norm. Now that I have been studying and experimenting with scripting for awhile this is easier to read and interpret (i.e. Visualize) how this works.


Froo

Post by Norm // Aug 30, 2007, 8:05am

Norm
Total Posts: 862
pic
I'll definitely be able to make use of this in my current scripting project. Thanks Norm. :)

Say you wouldn't happen to have that scene traversing one handy would ya? ;)

-Jack.

Right now am experimenting a little with trying to call a function from a button as requested in another thread: http://forums1.caligari.com/truespace/showthread.php?t=3976

Peter suggests that button script acts like a script command ...

Post by Norm // Aug 30, 2007, 10:16am

Norm
Total Posts: 862
pic
Ok, here is interesting twist on the scenario from Vladimir'juan'kanobie

fn = Node.AccessFnSet("/Project/FnSet Demo1/MyTest");
fn.MyTest();

and

fn = Node.AccessFnSet("/Project/FnSet Demo1/MyTest");
fn.YourTest();

So Vladimir's example shows the creation of a function set script, then placing buttons on it to call member functions!

It is pretty path dependent now. You would have to tweak the path if anything changed or if you wished to traverse different spaces.

fn = Node.AccessFnSet("%THIS_NAME%");
fn.MyTest();

So programming the buttons on interface and exchange the first line with the one above, makes the script portable to a degree. :)

Post by stan // Aug 30, 2007, 10:58am

stan
Total Posts: 1240
pic
thanks Norm, for showing us this..:banana:

Post by Norm // Aug 31, 2007, 6:23am

Norm
Total Posts: 862
pic
You are all most welcome.
It is a powerful scenario that can be interesting over time to see how they are used.

Post by Norm // Aug 31, 2007, 9:41am

Norm
Total Posts: 862
pic
Here is a scenario with scripted buttons calling thier own objects/themselves and also calling other function sets ....

Post by Délé // Aug 31, 2007, 10:05am

Délé
Total Posts: 1374
pic
Cool stuff Norm! Thanks for sharing! :D

Post by 3dvisuals dude // Sep 2, 2007, 10:01am

3dvisuals dude
Total Posts: 1703
pic
Here is a scenario with scripted buttons calling thier own objects/themselves and also calling other function sets ....

Thanks Norm! This is awesome and really useful!!!:banana:

- Mark / 3dvisuals dude
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