using script to access UI elements

Scripting questions, discussions, etc
  • 1
  • 2
11 posts Page 1 of 2
Online bsisko
Posts: 45
Joined: Mon Jun 19, 2017 7:28 pm
by bsisko » Mon May 28, 2018 5:15 am
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.
dstanton
Posts: 11
Joined: Thu Apr 19, 2018 5:47 pm
by dstanton » Tue May 29, 2018 6:48 am
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.
Duion
Posts: 1277
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Tue May 29, 2018 9:19 am
Can't you update any GUI at any time through scripts? You just pick the name of the GUI, a value in it and set it to something in script, then it will update.
dstanton
Posts: 11
Joined: Thu Apr 19, 2018 5:47 pm
by dstanton » Tue May 29, 2018 11:57 am
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.
Online bsisko
Posts: 45
Joined: Mon Jun 19, 2017 7:28 pm
by bsisko » Tue Mar 05, 2019 6:39 am
Duion,

Can you be a little more specific about what yo mean about updateing the GUI
Duion
Posts: 1277
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Tue Mar 05, 2019 5:30 pm
For example I have a backgroundGui that I replace with random background images through script every time you enter the main menu:

https://github.com/Duion/Uebergame/blob ... it.cs#L216
Online bsisko
Posts: 45
Joined: Mon Jun 19, 2017 7:28 pm
by bsisko » Fri Apr 12, 2019 5:03 am
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.
irei1as
Posts: 82
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Sat Apr 13, 2019 10:00 am
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/o ... ction.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/r ... ntrol.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.
Last edited by irei1as on Mon Apr 15, 2019 11:24 am, edited 1 time in total.
Online bsisko
Posts: 45
Joined: Mon Jun 19, 2017 7:28 pm
by bsisko » Mon Apr 15, 2019 4:11 am
Thanks irei1as,

I'll give it a try tonight!!
Online bsisko
Posts: 45
Joined: Mon Jun 19, 2017 7:28 pm
by bsisko » Mon Apr 15, 2019 5:33 am
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.
  • 1
  • 2
11 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 5 guests