Using buttons

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.

Using buttons // Scriptorium

1  |  

Post by Jack Edwards // Aug 29, 2007, 1:57pm

Jack Edwards
Total Posts: 4062
pic
I know I'm missing something obvious, but how do I link up a button on a brick to run code when pressed?


-Jack.

Post by stan // Aug 29, 2007, 2:25pm

stan
Total Posts: 1240
pic
button on a brick..you want to make a button control work..the properties tab of the button control panel has a place to write scripts..you get the panel when you right click on the actual button when the node is in edit mode..
you can run a boolean with the button to access some code only when its pressed too.[written as script in the properties panel] ;)

Post by Jack Edwards // Aug 29, 2007, 2:28pm

Jack Edwards
Total Posts: 4062
pic
Thanks stan. The boolean button is what I used for my morpher script. I didn't have any problems with that since I could link it to a variable like you mentioned.

Where I'm not following is what script do I type in the properties tab to make it run a function from inside that script brick.

Post by stan // Aug 29, 2007, 2:42pm

stan
Total Posts: 1240
pic
Jack I meant running a boolean in a regular button so it doesnt stay on.

the script you run is up to you and what you want it to do..as long as the button will handle it.

I use a boolean script in the button to switch on some line of code in the main script.... opens more possibilities....the boolean musr be an attribute in the main script..then switched off in the code controlled by the boolean

Post by stan // Aug 29, 2007, 2:48pm

stan
Total Posts: 1240
pic
in this project of mine you will find both types of use of the button control..http://forums1.caligari.com/truespace/showthread.php?t=3784 ..

Post by Jack Edwards // Aug 29, 2007, 3:00pm

Jack Edwards
Total Posts: 4062
pic
Lets say I have a function:


function test ()

{

System.Alert("Button pressed.");

}



How do I call that from here:

8174


The script box here seems to use a completely different syntax and scope than the script brick itself. :(


-Jack.

Post by stan // Aug 29, 2007, 3:04pm

stan
Total Posts: 1240
pic
just put;
System.Alert("Button pressed.");

that would work..just tried it..

Post by Jack Edwards // Aug 29, 2007, 3:10pm

Jack Edwards
Total Posts: 4062
pic
Yup that did execute. Ok so what I need to figure out then is the scope.


i.e. how to reference a function inside the brick from there.


-Jack.

Post by trueBlue // Aug 29, 2007, 3:14pm

trueBlue
Total Posts: 1761
pic
For a button I use this:
Activity.Run('%THIS_NAME%/MyScript')

%THIS_NAME% <- Using this in above is safer in case you rename your panel later where your MyScript resides.

It is suggested that you add a boolean to a Toggle Buttons.

Post by stan // Aug 29, 2007, 3:18pm

stan
Total Posts: 1240
pic
its not like c++.. that's why I use a boolean called in the button to access code bracketed in a boolean... the bool is from the main attribute list, setup in the main code...you can't access a bool attribute directly with a button control..

trueblue.thats a toggle control..they work differently..they stay on..

Post by Jack Edwards // Aug 29, 2007, 3:30pm

Jack Edwards
Total Posts: 4062
pic
Thanks trueBlue. You're closest to what I'm looking for. I don't need a boolean. I just want it to run a function from inside the brick when clicked.


I tried:

Activity.Run('%THIS_NAME%/test')


it doesn't give me an error but nothing happens either. :(


We're close to the solution on this one. It's gotta be something obvious.....


-Jack.

Post by trueBlue // Aug 29, 2007, 5:06pm

trueBlue
Total Posts: 1761
pic
I dunno works here, Here is an example. Have the Stack/Desktop open when you select any of these buttons.
Edit: Oooops sorry stan I was writing while you were posting.

Post by Jack Edwards // Aug 29, 2007, 5:36pm

Jack Edwards
Total Posts: 4062
pic
Ok. It looks like the Run.Activity() calls the "execute" function within an object.


For example:


function Execute(params)

{

Node.Value("/Preferences/Desktop", "BridgeSync") = "On"

}


Oh I get it. Activity.Run() only works on command scripts -- not script objects.


Ok. So we're back to the same question of how to scope to get access to functions inside a brick. I think this one is going to have to wait for one of the devs. :( I'll hunt though the developer docs and see if maybe something jumps out at me in the mean time.


I know there are other ways to achieve the code execution, but this is something that should be doable and it's been bothering me for well over a year now...

Post by Jack Edwards // Aug 29, 2007, 8:38pm

Jack Edwards
Total Posts: 4062
pic
Hmm.... I wonder if it's intentional that script objects cannot have their member functions called, since they are "static" objects and meant to process input/output through the linked values.


In which case the correct solution would be to use a separate command script to implement the button press and read the values off the script object, or to re-implement the whole object as a command script...


-Jack.

Post by Norm // Aug 30, 2007, 4:53am

Norm
Total Posts: 862
pic
Developers tell me you can try this (it works here btw):

Program the button with the function then call it like so:


function aaa()
{
System.Alert("button function call");
}
aaa();


The scripting for buttons is sort of isolated from script object code, so no way to simply call a member function from a button. Using this method, you can script the function in button proper and call it from there.

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

Jack Edwards
Total Posts: 4062
pic
Thanks Norm, but that won't allow me to access values stored in the script object. :(


So it looks objects with buttons need to be command scripts or have command scripts nested in them. Then use the Activity.Run() function like trueBlue posted.


Also Functions Sets would be useful here as well. Good thing I found this out before I got too far along, since the Exporter brick is obviously going to have to be a command script instead.


-Jack.

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

stan
Total Posts: 1240
pic
Jack thats why I said use a boolean in the button script with the activuty.run(which I forgot to mention) ..your other code must be setup to allow this ..if you don't want all the script to operate you will have to setup more booleans to isolate the main code..put a bool in the start button and use that bool in the main script to isolate it..its not a true function but you should be able to access one that way..

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

Norm
Total Posts: 862
pic
An interesting resolve from Vladimir: http://forums1.caligari.com/truespace/showthread.php?p=45831#post45831

Post by 3dvisuals dude // Aug 30, 2007, 10:33am

3dvisuals dude
Total Posts: 1703
pic
Please forgive me if this is considered off topic, it seems appropriate here to me though.

I have need for the ability to have a 3d object with several buttons on it activate a different script in relation to the function of a second 3d object in a scene.

In this case a Stargate (teleporter or server port actuator) is the second 3d object in the scene. The first 3d object with several 3d buttons on it would be the device determining which scripts were to apply to the second model after a button on the first model is left clicked. After left clicking one of those buttons, the avatar would approach the stargate model and a proximity sensor would then apply the previously selected script.

I am thinking that perhaps an array within a script pertaining to the 1st object, and containing the variable scripts of each button could then be linked as input to the proximity activator.

Is there an easy way to do this or a better approach I am not considering?

Thanks,

- Mark / 3dvisuals dude

Post by Jack Edwards // Aug 30, 2007, 11:11am

Jack Edwards
Total Posts: 4062
pic
Hi 3D, wouldn't it be easier to have an object that contains the button states then have your teleport script select based on the button states?


-Jack.

Post by Délé // Aug 30, 2007, 4:19pm

Délé
Total Posts: 1374
pic
Yeah, I'm working on something similar 3dvd. I'm making a teleportation machine with selectable destinations for the immersive environment comp.


The way I'm thinking of doing it is to have a script that sends different coordinates into the "Teleporter" script depending upon which button is pressed. Right now there is a script inside the teleportation trigger called "Teleport". That script collects the Avatar location/rotation or the user defined location/rotation and sends it into the "Teleporter" script. So I'm going to alter that script.


I'm going to make it so that it will collect 5 or 10 locations. Then it will have a number input. Inside will be an if/else statement or switch case, that will tell it which coordinates to output based on the input number. Then the 3d buttons will set that input number prior to activating the script. So if the user presses the first button, it will set the input to 1 and activate the script, which will in turn send the first coordinates to the "Teleporter" script. If the user presses the second button, it will set the input to 2 and activate the script, which will then send out the second coordinates to the "Teleporter" script. So on and so forth.


I have to make this script for my own project so I can send it along to you when I finish it if you want so you can hook it up for your stargate.

Post by Jack Edwards // Aug 30, 2007, 4:55pm

Jack Edwards
Total Posts: 4062
pic
Between Vladimir's FnSet examples and using Activity.Run() to access nested command scripts, I think I should be all set on this one. Thanks for the help guys, this has been something that I've been really stuck on for a while so it's definitely good to finally have it solved. :)


-Jack.

Post by 3dvisuals dude // Aug 31, 2007, 2:39am

3dvisuals dude
Total Posts: 1703
pic
Hi 3D, wouldn't it be easier to have an object that contains the button states then have your teleport script select based on the button states?

-Jack.

Yes! That would definitely be easier! Thanks!

I had a feeling there was something obvious that was hiding from me as I thought about all this, and that's gotta be it! LOL

I think it was Edgar Allen Poe, if I'm not mistaken, that said the best place to hide a thing is in plain sight! ("Murders in the Rue Morgue," I think;))

Thanks Jack, that saved me a bunch of time!:)

- Mark / 3dvisuals dude

Post by 3dvisuals dude // Aug 31, 2007, 2:49am

3dvisuals dude
Total Posts: 1703
pic
Yeah, I'm working on something similar 3dvd. I'm making a teleportation machine with selectable destinations for the immersive environment comp.

The way I'm thinking of doing it is to have a script that sends different coordinates into the "Teleporter" script depending upon which button is pressed. Right now there is a script inside the teleportation trigger called "Teleport". That script collects the Avatar location/rotation or the user defined location/rotation and sends it into the "Teleporter" script. So I'm going to alter that script.

I'm going to make it so that it will collect 5 or 10 locations. Then it will have a number input. Inside will be an if/else statement or switch case, that will tell it which coordinates to output based on the input number. Then the 3d buttons will set that input number prior to activating the script. So if the user presses the first button, it will set the input to 1 and activate the script, which will in turn send the first coordinates to the "Teleporter" script. If the user presses the second button, it will set the input to 2 and activate the script, which will then send out the second coordinates to the "Teleporter" script. So on and so forth.

I have to make this script for my own project so I can send it along to you when I finish it if you want so you can hook it up for your stargate.

Wow! Sounds like we were almost headed in the same direction on that one!

What you are describing here sounds much better and more elaborate than my idea for sure though!

Sorry if I ruined a surprise competition entry for you by my question here, I had no idea what you were up to! This sounds like it will be very useful for sure.

In reading your description above it sounds really great. If there's a possibility, it might also be way nice to have an input node for a bitmap image pertaining to each of the many destinations so folks could create screencaptures (using external editors) of the viewpoint from the eyecam at a given destination and then add them to a button icon pertaining to that destination, so folks could see at a glance which button to click. Maybe that would be good for a future version. What you described above sounds useful for many other things too!

- Mark / 3dvisuals dude

Post by 3dvisuals dude // Aug 31, 2007, 2:58am

3dvisuals dude
Total Posts: 1703
pic
Between Vladimir's FnSet examples and using Activity.Run() to access nested command scripts, I think I should be all set on this one. Thanks for the help guys, this has been something that I've been really stuck on for a while so it's definitely good to finally have it solved. :)

-Jack.

Well, as it turns out I'm really glad you started this thread too! These samples from Vladimir and the many great suggestions in thread will no doubt be very useful reference sources for others in time too.

Sorry if I kind of dragged it all off topic a bit though, but glad it all turned out to solve the issues you were having, as it sure did with mine.

Thanks Jack,

- Mark / 3dvisuals dude

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

Délé
Total Posts: 1374
pic
Between Vladimir's FnSet examples and using Activity.Run() to access nested command scripts, I think I should be all set on this one. Thanks for the help guys, this has been something that I've been really stuck on for a while so it's definitely good to finally have it solved.


Glad you got things working now Jack. I look forward to your exporter. Good luck on it. :)


Wow! Sounds like we were almost headed in the same direction on that one!


What you are describing here sounds much better and more elaborate than my idea for sure though!


Sorry if I ruined a surprise competition entry for you by my question here, I had no idea what you were up to! This sounds like it will be very useful for sure.


In reading your description above it sounds really great. If there's a possibility, it might also be way nice to have an input node for a bitmap image pertaining to each of the many destinations so folks could create screencaptures (using external editors) of the viewpoint from the eyecam at a given destination and then add them to a button icon pertaining to that destination, so folks could see at a glance which button to click. Maybe that would be good for a future version. What you described above sounds useful for many other things too!


No no, there are no ruined surprises. I do have a few up my sleeve though. Hopefully I can get it done in time. :) Yeah, it looks like we have pretty much the same idea in mind. I'm actually going to have a bitmap displaying the chosen teleportation area too.


I've attached a teleportation trigger that lets you capture up to 5 locations. Then in the script for your buttons you would write the following:


Node.Value(Space.CurrentScene() + "/Teleportation Trigger Select/Coord Pick", "Number") = 1;

Activity.Run(Space.CurrentScene() + "/Teleportation Trigger Select/Coord Pick");


The first line sets the "Coord Pick" script input to the desired number and the second line activates the script to update the coordinates. So on your first button, you would want to enter 1 at the end of the first line so the avatar gets teleported to the first coordinate. On your second button enter 2 at the end of the first line, etc., etc.


This is path dependent so if you change the name of the teleporter, make sure you change the name in the script for your buttons too.


hth

Post by Norm // Aug 31, 2007, 10:14am

Norm
Total Posts: 862
pic
Space.CurrentScene()
I have been scouring the known world for this over past few days.
That is exactly the way to make some scripts a little less path dependent :):banana:

Post by trueBlue // Sep 2, 2007, 12:06am

trueBlue
Total Posts: 1761
pic
This is path dependent so if you change the name of the teleporter, make sure you change the name in the script for your buttons too.
hth
Dele: I finally figured out how to strip the path from the Panel's name.

Post by 3dvisuals dude // Sep 2, 2007, 8:55am

3dvisuals dude
Total Posts: 1703
pic
No no, there are no ruined surprises. I do have a few up my sleeve though. Hopefully I can get it done in time. :) Yeah, it looks like we have pretty much the same idea in mind. I'm actually going to have a bitmap displaying the chosen teleportation area too.

I've attached a teleportation trigger that lets you capture up to 5 locations. Then in the script for your buttons you would write the following:

Node.Value(Space.CurrentScene() + "/Teleportation Trigger Select/Coord Pick", "Number") = 1;
Activity.Run(Space.CurrentScene() + "/Teleportation Trigger Select/Coord Pick");

The first line sets the "Coord Pick" script input to the desired number and the second line activates the script to update the coordinates. So on your first button, you would want to enter 1 at the end of the first line so the avatar gets teleported to the first coordinate. On your second button enter 2 at the end of the first line, etc., etc.

This is path dependent so if you change the name of the teleporter, make sure you change the name in the script for your buttons too.

hth

WOW!!!!:banana:

This is GREAT!!! Thanks Délé!!! You just created a tool here we're all going to have a blast with very soon!!! Just wait 'till you see what I'll be presenting early next Tuesday night and how that will all work with this, you're gonna love it!:D

I have a surprise I've created for everyone which if I have it ready (and I should;) ) I'll be rolling out at Tuesday night's meeting too, and this one will be something we will all love to use too, even Roman!:D

You're making enormous strides here for all of us with all these fantastic new immersive scene development tools of yours lately! I hope you're enjoying that as much as I am 'cause I'm lovin' every minute of it!!! Great stuff!

Thanks!

- Mark / 3dvisuals dude

Post by 3dvisuals dude // Sep 2, 2007, 9:06am

3dvisuals dude
Total Posts: 1703
pic
Dele: I finally figured out how to strip the path from the Panel's name.



Path in - Name out = I love this! Thank's for another great tool trueBlue!

This will help us all with quick fixes on a bunch of path related mods to make older scripts functional too aside from being a great new default for all our new scripts! Excellent work!

Thanks!: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