GuiTextEditCtrl problem
by Aaron Goselin · in Torque Game Builder · 02/05/2007 (3:47 pm) · 7 replies
Hi :)
I don't quite understand it yet, but I can't figure out how to get a GuiTextEditCtrl to accept enter and excecute a function. For example I'd like to be able to type something into the text control and hit enter, and then have the script do something with what's in the control. I've been searching for the answer to this for over 3 hours now...don't know if I'm just too tired to day or what... I've searched for key catching, keydown, onkey, key capturing, onEnter (which wasn't what I was thinking lol), and so many more things. If you could give me an answer I could stop having to wipe the blood off my monitor (hitting your head = bad.)
Thanks :)
(Yes I already posted this in another section but both sections seemed relevant to my problem and I find it VERY difficult to get timely help on this forum. If anyone knows of a better form PLEASE tell me.)
I don't quite understand it yet, but I can't figure out how to get a GuiTextEditCtrl to accept enter and excecute a function. For example I'd like to be able to type something into the text control and hit enter, and then have the script do something with what's in the control. I've been searching for the answer to this for over 3 hours now...don't know if I'm just too tired to day or what... I've searched for key catching, keydown, onkey, key capturing, onEnter (which wasn't what I was thinking lol), and so many more things. If you could give me an answer I could stop having to wipe the blood off my monitor (hitting your head = bad.)
Thanks :)
(Yes I already posted this in another section but both sections seemed relevant to my problem and I find it VERY difficult to get timely help on this forum. If anyone knows of a better form PLEASE tell me.)
About the author
#2
02/06/2007 (9:39 am)
Ok thanks I'll take a look at it. I've asked questions in the past that have taken forever or simply gotten nothing at all. I just hate message boards I guess... I usually try every other avenue before posting on a board. Unfortunately I almost always tend to miss something obvious.
#3
"... 23:28 GMT. You can set a shortcut key for a button by filling in its "accelerator"
field. In this case, you'd just want it to be "enter" You'll probably also ... "
which sounds absolutely perfect. Of course when I click on it I get:
"Sorry, only members who have purchased the following products may access this discussion:"
and it of course lists all TGE stuff. I still do not understand why I should be locked out of TGE information? I mean...what am I going to do with it? It's the same engine except with 3D in it isn't it?
So to summarize, it looks like I found the answer to a question, but I can't get it for reasons unknown to me.
--- End rant / explanation ---
Anyway using Accelerator on a button doesn't work. I'm completely confounded too because if you set an EscapeCommand like error("Button pressed"); it prints the error when you hit escape, but setting the accelerator to enter or escape doesn't work like it seems it is supposed to.
Any ideas on why Accelerator doesn't seem to be functioning for me?
02/06/2007 (11:28 pm)
Ok, here's an example of where my frustration comes from. I've been looking into the chat gui like you suggested and playing around with everything they've done. Simple enough, except it doesn't seem to work in any way. So I decided to start searching for accelerator on the GG site. Eventually working out the search "accelerator -video -graphics" I see the first post says:"... 23:28 GMT. You can set a shortcut key for a button by filling in its "accelerator"
field. In this case, you'd just want it to be "enter" You'll probably also ... "
which sounds absolutely perfect. Of course when I click on it I get:
"Sorry, only members who have purchased the following products may access this discussion:"
and it of course lists all TGE stuff. I still do not understand why I should be locked out of TGE information? I mean...what am I going to do with it? It's the same engine except with 3D in it isn't it?
So to summarize, it looks like I found the answer to a question, but I can't get it for reasons unknown to me.
--- End rant / explanation ---
Anyway using Accelerator on a button doesn't work. I'm completely confounded too because if you set an EscapeCommand like error("Button pressed"); it prints the error when you hit escape, but setting the accelerator to enter or escape doesn't work like it seems it is supposed to.
Any ideas on why Accelerator doesn't seem to be functioning for me?
#4
Credit goes to Matthew Langley for posting www.garagegames.com/mg/forums/result.thread.php?qt=31881.
Thanks for your help, you pointed me in the right direction.
02/07/2007 (12:12 am)
Ok I seem to have found a solution. Apparently I needed to use AltCommand (who knew?) and for some reason I had never tried it to see what it does.Credit goes to Matthew Langley for posting www.garagegames.com/mg/forums/result.thread.php?qt=31881.
Thanks for your help, you pointed me in the right direction.
#5
02/07/2007 (12:51 am)
A quick note: I noticed that I would start up my program, add the text box and then try it and everything would work...but then after I shut down TGB and started it up again the text box wouldn't do what I wanted. After trying a few things it seems that it was doing this because I was testing on the mainscreen gui and I guess it doesn't like that.
#6
The best practice is, after saving your changes to mainScreenGui.gui, to restart TGB. You can do this from the Level Editor by selecting File->Open Project and selectiing your project in the Open Project window. Or just quit the application and restart. The project you most recently working on will be automatically opened.
The reason things are so weird with mainScreenGui.gui is that the file is read in via exec() in the initializeProject() function defined in main.cs. This means that unlike the functions you define via exec() in the startGame() function of game.cs, the Gui defined in mainScreenGui.giu (the object's name is mainScreenGui) is not re-read from disk every time you run your game.
Another gotcha is that the name of the Gui object ("mainScreenGui") is built right in to Level Editor (see the code for function hideLevelEditor() in ~/games/tools/levelEditor/main.cs). This means that your main Gui object must have that very name; you cannot change it to, say, myMainScreen, and expect the Level Editor to continue to work properly for you.
The situation is complex and potentially confusing, and I apologize if I have not done a good job of explaining it clearly.
In my own work, I decided to exec() mainScreenGui.gui from my exec.cs, which is itself exec()'d every time the startGame() function (in game.cs) is called. This means the Gui is read in from disk every time I run the game. Consequently, I can edit mainScreenGui.gui in my text editor directly, just like any other of my source files. Or I can use Gui Editor, but I have to be careful to save my changes, which I now do out of habit.
The only down side is that the Gui Editor's Gui menu (the middle pop-down menu) gradually fills up with multiple copies of mainScreenGui: I have to be careful to select the last entry by that name from the menu.
Bonne chance!
02/07/2007 (10:34 pm)
Aaron Goselin wrote:Quote: I would start up my program, add the text box and then try it and everything would work...but then after I shut down TGB and started it up again the text box wouldn't do what I wanted. ...it seems that it was doing this because I was testing on the mainscreen gui...It is possible that you were experiencing difficulties because of either failing to save the changes you made to mainScreenGui.gui in the Gui Editor, or because of that file's special status in TGB.
The best practice is, after saving your changes to mainScreenGui.gui, to restart TGB. You can do this from the Level Editor by selecting File->Open Project and selectiing your project in the Open Project window. Or just quit the application and restart. The project you most recently working on will be automatically opened.
The reason things are so weird with mainScreenGui.gui is that the file is read in via exec() in the initializeProject() function defined in main.cs. This means that unlike the functions you define via exec() in the startGame() function of game.cs, the Gui defined in mainScreenGui.giu (the object's name is mainScreenGui) is not re-read from disk every time you run your game.
Another gotcha is that the name of the Gui object ("mainScreenGui") is built right in to Level Editor (see the code for function hideLevelEditor() in ~/games/tools/levelEditor/main.cs). This means that your main Gui object must have that very name; you cannot change it to, say, myMainScreen, and expect the Level Editor to continue to work properly for you.
The situation is complex and potentially confusing, and I apologize if I have not done a good job of explaining it clearly.
In my own work, I decided to exec() mainScreenGui.gui from my exec.cs, which is itself exec()'d every time the startGame() function (in game.cs) is called. This means the Gui is read in from disk every time I run the game. Consequently, I can edit mainScreenGui.gui in my text editor directly, just like any other of my source files. Or I can use Gui Editor, but I have to be careful to save my changes, which I now do out of habit.
The only down side is that the Gui Editor's Gui menu (the middle pop-down menu) gradually fills up with multiple copies of mainScreenGui: I have to be careful to select the last entry by that name from the menu.
Bonne chance!
#7
Thanks for the info.
02/12/2007 (2:44 am)
Ok I pretty much get what you are saying. I don't think I need to do that for what I'm working on right now, but I'll definately keep that information filed under things I should know. I create all my new functions in a new project and then transfer things over, so I just put everything onto a different GUI to skip the problem alltogether. AltCommand works great for the moment, so I'm ok :) Thanks for the info.
Torque Owner Andrew Douglas
Anyway, I thought I'd see if there were any examples of hitting enter in a textbox to cause an event to fire and the first GUI I thought of was the chat gui (in the common\gui directory - i'm assuming you have that)... and it was pretty clear what they were doing. If you don't want to use the accelerator="return" on a button like they do, then maybe it'll give you some ideas about how to go about it. Hope this helps.
-Andrew