Jump to content

using script to access UI elements


bsisko

Recommended Posts

Is there a way to use script to code UI elements?


For example, I have a GUIImage on the MainMenu GUI.

I want to use script that when a mouse click is resgistered on the control, it will execute the code to change images like

GUIImage.Picture = filename.


BTW, I am not at my work computer, so the above references are not correct, but approximations of what I know about Torque.

Link to comment
Share on other sites

Certain GUI elements are updated on an action event, (ammo in the FPS demo, etc) . If you take a look at these events, you'll get a better idea of how it all works. I know theres a onObjectSelected(%this, %obj) event method, not sure if the scope exists on all GUI elements or what, but after it would be called, the main GUI element is stored in the %this variable and you're able to dig into the object further. A lot of these events and object properties can be found in the Torque documentation, found on google, you just have to keep in mind the object you're referencing.

Link to comment
Share on other sites

I'm going to add that I am not the sharpest programmer, and I might have to take back what I had commented earlier. onObjectSelected(%this, %obj) isn't a GUI function and should be ignored. Some of what I said should make a little more sense when you get to know the system more.

Link to comment
Share on other sites

  • 9 months later...
  • 1 month later...

Okay here is what I have!


I have an GUIBitmapCtrl and GUIButtonCtrl in my PlayGUI.

In my files I have a function named DeSign in my Game.cs script file

In the playGUI, I have the GUIBitmapCtrl properties set as:

position = 34 39

extent = 549 640

What I want to do is when I click on the GuiButtonCtrl button I want to shrink the GUIBitmapCtrl control to the lower right hand corner by setting the properties like this

position = 500 400

extent = 100 200

and make the GUIButtonCtrl disappear by setting its visible property to false. I have in the command property tab of the GUIButtonCtrl the name of the function DeSign.

Link to comment
Share on other sites

First you need to give the pair of gui objects global names (there are other ways to do it but global names are the easiest).


To set the name write it in its place in the gui editor.

http://docs.garagegames.com/torque-3d/official/content/documentation/GUI%20Editor/Overview/Introduction.html

You can see the global name box in the picture. It says

OptPostFxTo.


Let's say you named them 'MyButton' and 'MyBitmap'.


Inside the 'DeSign' function that is called when you click the button you add:


MyBitmap.setPosition(500,400);

MyBitmap.setExtent(100,200);

MyButton.setVisible(false);


Those functions are from gui in general as you can see in

http://docs.garagegames.com/torque-3d/reference/classGuiControl.html


Note the format

GlobalName.methodName(params);


If it doesn't work be sure to check the console for errors. Some name might be misspelled or a ; could be hanged somewhere. Check all the console for red messages.


Edit: that documentation is a bit old but it works.

For extra help you may want to check http://wiki.torque3d.org/main:documentation or look at some posts around in this forum.

Edited by irei1as
Link to comment
Share on other sites

I have the function in the game.cs file that is located in the server directory. It is exec'ed (or supposed to be exec'ed) by the main.cs file in the game folder (not the main.cs file in the example folder.) Nevertheless, the console reports that it cannot find the function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...