Reassignment of class to objects during runtime
by Demolishun · in Torque Game Engine · 09/14/2004 (8:48 pm) · 6 replies
Hello,
What I am doing is trying to create my own scripting environmant inside the Torque GUI. Right now I can open, edit, save, and execute scripts all within the GUI. I look at the console to pick up on errors. I will eventually pipe the errors to a scrolled text widget at the bottom of the screen for easy access. My goal for this little scripting project is to create a VB type interface for Torque script. I want to make windows that show scripts, debugging info, widget selection, etc. I will be adding to this as I need a feature. I am developing something else, but this side project is quite nice even in its initial form.
I am having trouble with one aspect of the scripting engine. I want to be able to redefine datablocks and objects during the development process. I got an error when trying to run a script indicating that the class definition could not be redefined. I found that if I declared a datablock as one type then reran the same script with a different type of datablock it would complain. Can this be changed without restarting Torque?
BTW, on a different subject. How do I create and show GUI controls created in script? How do I parent them to an existing control? I have been looking at the code for the GUI editor, but so far nothing really stands out.
Thanks for any help you can provide,
Frank
What I am doing is trying to create my own scripting environmant inside the Torque GUI. Right now I can open, edit, save, and execute scripts all within the GUI. I look at the console to pick up on errors. I will eventually pipe the errors to a scrolled text widget at the bottom of the screen for easy access. My goal for this little scripting project is to create a VB type interface for Torque script. I want to make windows that show scripts, debugging info, widget selection, etc. I will be adding to this as I need a feature. I am developing something else, but this side project is quite nice even in its initial form.
I am having trouble with one aspect of the scripting engine. I want to be able to redefine datablocks and objects during the development process. I got an error when trying to run a script indicating that the class definition could not be redefined. I found that if I declared a datablock as one type then reran the same script with a different type of datablock it would complain. Can this be changed without restarting Torque?
BTW, on a different subject. How do I create and show GUI controls created in script? How do I parent them to an existing control? I have been looking at the code for the GUI editor, but so far nothing really stands out.
Thanks for any help you can provide,
Frank
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67
#2
Coincidentally, the "InspectDlg" GUI also has a dynamic section where buttons are added and removed from the GUI via script. So I'd say both of your problems can be tackled right there.
EDIT: I don't believe it's possible to actually reassign the class of a datablock without first deleting it as Ben suggested.
09/14/2004 (10:55 pm)
The "InspectDlg" GUI allows you to view and change a datablock dynamically. I would start there for the proper setup an code to do that because it works great.Coincidentally, the "InspectDlg" GUI also has a dynamic section where buttons are added and removed from the GUI via script. So I'd say both of your problems can be tackled right there.
EDIT: I don't believe it's possible to actually reassign the class of a datablock without first deleting it as Ben suggested.
#4
No, I do not know how to keep track of the object, datablock, etc so I can delete them.
This is how my code works currently:
1. Edit code in a text widget within the Torque IDE.
2. Run eval on the contents of the text widget and view errors, output, etc in the console.
Is there a way to keep track of the objects, datablocks, etc created by the script so I can destroy them? Is there some kind of pre/post-processor to go through the code to make of list of objects that will be created? The intent of this code is so the coder does not have to deal with the details of what is produced by a run. Maybe I need a button that will destoy all objects, datablocks, etc when I need to rerun the code. Then I need a list of objects that I can generate to go through and wack all the old objects.
I will have to search the forums for an example of using sim groups.
That brings me to another question. Do I just tell a group of objects to save themselves into a "cs" file? For instance I go to the root object such as a window and object.save("filename")?
Gonzo,
I will look at InspectDlg. I have also been looking at objects with the edit GuiEditCtrl type. I can create an object with the built in "editor" widget name, but when I create my own based on the GuiEditCtrl type and try to connect it crashes Torque. I have been using the "addNewCtrl" function to attach my widget.
Erik,
I will look at that resource and compare what I am doing to that code. It should give me some good ideas for what I am doing.
One more question on the GUI text edit widgets:
I noticed that the widget will automagically grow vertically when I add more text than what is possible to display on the intially allocated area. However, I cannot seem to get it to grow horizontally. Is there a setting or should I just make the buffer super wide to start. The wrapping text is really annoying and will cause confusion.
Thank you all,
Frank
09/15/2004 (8:11 pm)
Ben, No, I do not know how to keep track of the object, datablock, etc so I can delete them.
This is how my code works currently:
1. Edit code in a text widget within the Torque IDE.
2. Run eval on the contents of the text widget and view errors, output, etc in the console.
Is there a way to keep track of the objects, datablocks, etc created by the script so I can destroy them? Is there some kind of pre/post-processor to go through the code to make of list of objects that will be created? The intent of this code is so the coder does not have to deal with the details of what is produced by a run. Maybe I need a button that will destoy all objects, datablocks, etc when I need to rerun the code. Then I need a list of objects that I can generate to go through and wack all the old objects.
I will have to search the forums for an example of using sim groups.
That brings me to another question. Do I just tell a group of objects to save themselves into a "cs" file? For instance I go to the root object such as a window and object.save("filename")?
Gonzo,
I will look at InspectDlg. I have also been looking at objects with the edit GuiEditCtrl type. I can create an object with the built in "editor" widget name, but when I create my own based on the GuiEditCtrl type and try to connect it crashes Torque. I have been using the "addNewCtrl" function to attach my widget.
Erik,
I will look at that resource and compare what I am doing to that code. It should give me some good ideas for what I am doing.
One more question on the GUI text edit widgets:
I noticed that the widget will automagically grow vertically when I add more text than what is possible to display on the intially allocated area. However, I cannot seem to get it to grow horizontally. Is there a setting or should I just make the buffer super wide to start. The wrapping text is really annoying and will cause confusion.
Thank you all,
Frank
#5
To keep track of your blocks, just use this type of stuff...
Lets say you want to create blocks while your editor is open, and have them go away when you close the editor, then upon editor open you would use...
if(!isObject(MyNewBlocks)) { new SimGroup("MyNewBlocks"); }
Every time a new block is created you'll want to add it to your group by name via...
%block = SomeNewBlock{};
MyNewBlocks.add(%block);
And then when you close your editor out you would use...
MyNewBlocks.delete();
to get rid of everything when the editor closes. Otherwise set up a button to delete them and let the group hang out till done.
If you create some blocks that you want to save to a .cs file then you can easily export them all by using...
MyNewBlocks.save("common/myblocks/MyNewBlocks.cs");
Good luck
09/16/2004 (5:22 am)
Frank, simgroups are easy.To keep track of your blocks, just use this type of stuff...
Lets say you want to create blocks while your editor is open, and have them go away when you close the editor, then upon editor open you would use...
if(!isObject(MyNewBlocks)) { new SimGroup("MyNewBlocks"); }
Every time a new block is created you'll want to add it to your group by name via...
%block = SomeNewBlock{};
MyNewBlocks.add(%block);
And then when you close your editor out you would use...
MyNewBlocks.delete();
to get rid of everything when the editor closes. Otherwise set up a button to delete them and let the group hang out till done.
If you create some blocks that you want to save to a .cs file then you can easily export them all by using...
MyNewBlocks.save("common/myblocks/MyNewBlocks.cs");
Good luck
Associate Kyle Carter
GUI controls are SimGroups so you should be able to add/remove just like with a SimGroup.