Game Development Community

dev|Pro Game Development Curriculum

In-Game Script Editor

by Marcus L · 11/18/2010 (10:24 pm) · 44 comments

Tested on: 1.1b3

This resource will add a new tool, the script editor, to the world editor's toolbar. I made this resource because of the time i spend closing and opening T3D, which was extremely time consuming. And even tho I'm able to exec the scripts after i change them in torsion, it is not the optimal solution. Therefore i created the in-game script editor. Just so that's said; atm. this editor is very simple and does not even support undoing yet. This doesn't mean this is useless, it just means you should probably not use it for complex coding (for the time being).

Installation:


First, start of by downloading this .rar.
Extract it to game/tools.

Then, this is how to install the rest of this resource:
Where it says // Added, it means that the line is added.
Where it says // Removed, it means that the line is removed.
Where it says // Changed, it means that the line is changed.
Where it says ..., it means that there is code between what ever that was last written.
Whenever it says ..., there will be an comment below describing what function it is.

I recommend you using CTRL + F to find where to put the code blocks. Remember to backup before installing.

We'll start by editing core/scripts/client/helperfuncs.cs
// Put below function loadFileText( %file)
// Added ->
function saveFileText( %file, %text )
{
   // File Object
   %fo = new FileObject();
   %fo.OpenForWrite(%file);
   
   // Write Text
   %fo.writeLine(%text);
   
   // Clean Up
   %fo.delete();
   return %text;
}
// Added <-

Then edit tools/worldEditor/gui/ToolsToolbar.ed.gui
//In the beginning of the gui
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiContainer(EWToolsToolbar) {
   canSaveDynamicFields = "0";
   Enabled = "0";
   internalName = "ToolsToolbar";
   isContainer = "1";
   Profile = "editorMenubarProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   Position = "0 31";
   //MXG: 14 is the number of tools, change if you have more
   Extent = (29 + 4) * 14 + 12 SPC "33"; // Changed
   MinExtent = "8 2";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";
   isClosed = "0";
   isDynamic = "0";

Last, edit tools/worldEditor/scripts/EditorGui.ed.cs
...
//In function EditorGui::init(%this)
         EWInspectorWindow.setVisible( false );
      }
   } 
   
   // Added ->
   if( !isObject( %this-->ScriptTreeWindow ) )
   {
      // Load Creator/Inspector GUI
      exec("~/scriptEditor/scriptEditorGui.gui");
      if( isObject( EWScriptTreeWindow ) )
      {
         %this.add( EWScriptTreeWindow );
         EWScriptTreeWindow-->EditorTree.selectPage( 0 );
         EWScriptTreeWindow.setVisible( false );
      }
   }
   // Added <-
...
//Same
   EWorldEditor.init();
   ETerrainEditor.init();

   //Creator.init();
   EWCreatorWindow.init();
   EWBrowserWindow.init(); // Added

Now just enter any level,
Press F11,
And you'll see a new icon in the toolbar,
Press it,
And you'll have a TextPad window and a FileTree on the side.

You'll now see that you have a Save button, a Close Button and a Refresh button.
The Save button will save any change you've made to the current script.
The Close button will close the TextPad. This can be restored by opening any script. Also note that whenever you're closing the TextPad it'll ask you if you want to save, even tho you've not made any change.
The Refresh button will automatically save you're file and execute it. Note that the save button will not execute.

The FileTree is just like the mesh selector from the Object Editor. It will by default only search for .cs and .gui files. This can be changed in the Edit->Editor Settings... dialog.

Screenshot:

img502.imageshack.us/img502/20/scripteditor2j.pngRight click->view image for full size (it got cut off).


This resource is actually "Known Issue" free =). But there is a lot of room for improvement. Here is a list for those who want to help me improve this resource:
  1. Undoing
  2. Proper file tree
  3. Code markup
  4. File tree right click context menu
  5. Auto-Complete-Me (IntelliSense)
Hopefully, someone from the community will help to improve this resource, and maybe the Torque dev team could include this functionality in future builds I'm aware that this is not the time!

If you stumble upon some issues, let me know.
Also know that my methods might not be correct, nor the most professional. Therefore if you see some silly mistakes please leave a comment with the "fix".

Thanks,
Marcus L.
#21
11/21/2010 (5:42 pm)
@Daniel
NP, =D

@Michael
Hah, never thought of actually integrating an opensource text editor into torque. This fact maybe saved me some time :P. Np anyways =).

I feel like i should maybe add the undo manager... Unfortunately i have no experience with it so if anyone knows how it works, can you give me some hints? or just do it for me :P?
#22
11/21/2010 (7:36 pm)
This is a fantastic resource! Great job Marcus. I'm going to have to incorporate this in my personal project.
#23
11/22/2010 (7:35 pm)
Yaa Marcus! Your my Hero!
#24
11/22/2010 (8:22 pm)
@Michael
Never thought a torque dev would respond :P, *feels honored*! Thanks Michael =D.

@JesseL
=)

I'm really hoping people will get a use of this. I'll try as much as i can to improve this resource so you might want to check the notification checkbox to be up to date ^_^
#25
11/29/2010 (9:29 pm)
Super Cool!

Can't believe something like this wasn't already implemented.
#26
12/02/2010 (7:46 pm)
Great work Marcus, it is something I can use. Thanks.
#27
12/02/2010 (8:01 pm)
@J
Yeah, i know :D

@Richard
Np =)
#28
12/12/2010 (7:15 pm)
I don't know what I'm doing wrong, but it's not working correctly.
The biggest problem is that scriptEditor/main.cs is calling
exec( "./scriptEditorGui.cs" );
and there isn't a scriptEditorGui.cs in the .rar that I downloaded. What am I missing?

The file tree isn't showing up and the toolbar buttons are messed up.
#29
12/12/2010 (8:22 pm)
Hmm, strange, the exec you posted is only something i forgot to remove before uploading.

What version are you on?
What errors do you get in the console?

You can maybe send a picture & the console log for me to be able to help you properly.
#30
12/13/2010 (11:14 pm)
I'm using 1.0.1. I guess that must be the problem. I wouldn't have thought it would be very different.

My console errors:
121: Cannot re-declare object [DecalEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
163: Cannot re-declare object [MeshRoadEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
#31
12/13/2010 (11:17 pm)
...
163: Cannot re-declare object [RiverEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
144: Cannot re-declare object [RoadEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
#32
12/13/2010 (11:18 pm)
...
102: Cannot re-declare object [ShapeEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
213: Cannot re-declare object [TerrainEditorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
#33
12/13/2010 (11:34 pm)
...
14: Cannot re-declare object [TerrainPainterPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
98: Cannot re-declare object [WorldEditorInspectorPalette].
tools/worldEditor/gui/ToolsPaletteGroups/init.cs (36): Unable to find object: '0' attempting to call function 'getCount'
...
tools/scriptEditor/main.cs (78): Unable to find object: '0' attempting to call function 'setVisible'
#34
12/14/2010 (5:27 pm)
Those errors look strange, I'm not sure why you'd get error in ToolsPaletteGroups/init.cs when you're not even touching those folders throughout this resource. Unfortunately, I'll have no time the next days to port this over to 1.0.1 to fix this issue, think I'll be able during the weekend...
#35
12/14/2010 (5:28 pm)
comment bug Dx
...If you want to look into this issue yourself, I'd recommend; First, to try this resource in 1.1b3 to see if it works. Second, compare the tools/ folder from 1.1b3 with the tools/ folder from 1.0.1 and see if you find something suspicious.
#36
12/14/2010 (11:44 pm)
I'll see what I can do.
As far as I know, I can't download 1.1b3 because I have Binary, not Pro.
#37
12/15/2010 (12:43 am)
@jonathan: 1.1 B3 was released to binary recently I believe.
#38
12/15/2010 (3:22 am)
Oh, you're right it has :)
Thanks!
#39
02/11/2011 (5:48 am)
This is greate ! bt i can't download it, it shows just a blank page =(
Can someone please e-mail it to me ? bushmils@live.ru
#40
02/11/2011 (10:42 am)
Hmm, works for me but sure, E-mailing it now =)

This reminds me that i should probably update this soon also