[XP][VX] Using External IDE as a Script Editor

Started by ForeverZer0, June 18, 2011, 02:31:21 pm

Previous topic - Next topic

ForeverZer0

June 18, 2011, 02:31:21 pm Last Edit: July 23, 2011, 11:13:41 pm by ForeverZer0
Using External IDE as a Script Editor
Author: ForeverZer0




As many of you may know, the script editor is very basic and does not have a lot of rich features like other IDEs.  While it is not difficult to write a script in another program like Notepad++, Eclipse, Netbeans, Visual Studio, etc., it is a major pain to constantly copy-paste the script into the editor every time you want to playtest or debug the script.  Having to do so dramatically slows down development, and usually stops most from even bothering with it.  The point of this tutorial is to show you how you can do it and still have the best of both worlds.  The ability to use an external IDE, and still be able to simple click a button to start testing it.



Setting up Notepad++

For this tutorial, I will be using a Notepad++ as our IDE of choice, although the same concept can be applied to nearly all IDEs.  Notepad++ is probably the best overall compromise of power and overhead.  It integrates smoothly into Windows and supports syntax of nearly every language you will find yourself using.  There are a ton of features in Notepad++, but for the point of this tutorial I will be simply explaining how to set it up as a RMXP script editor.

Alright, so first thing first. You will need to install Notepad++. Once you have it installed, go ahead and open it.  There are many useful tweaks that you can make to improve and customize how you want the IDE to behave and allow you to be the most productive, and even setting themes and altering the colors used for different syntaxes.  Go ahead and play around and tweak the settings to try different things out.  Once your done, go to the menu bar and click the "Plugins" option, scroll down to "Plugin Mangager", then select "Show Plugin Manager"

Spoiler: ShowHide


From here you will be presented with a screen listing many various plugins available for download, which you can explore later, but for now we are looking for "NppExec", so scroll down a bit under the "Available" tab and find it.  Once found, check it and click the "Install" button.

Spoiler: ShowHide


Once it has installed and Notepad++ has restarted, you are very close to completion of this portion of the process. Now select the "Plugins" tab again, and you will "NppExec" listed there now, so select it.  There are some various options available, I would suggest checking the "Save all files on execute" option to make things easier on yourself.

Spoiler: ShowHide


After that, select the top option, or simply press F6 from the main screen to bring up the execution dialog.  Here we need to make a command to execute our RMXP game.  It should follow this pattern:
cmd.exe /c " <FULL PATH TO PROJECT'S GAME.EXE> "

You can label it however you want to keep track of multiple projects you may be working on.

Spoiler: ShowHide


Press "OK" to test it out and you should see your game start up.  From this point on you can simply click "Ctrl + F6" to quickly execute the last command from the editor without the need to navigate to this menu.  This is the conclusion of this part of the tutorial, now we just need to make a tweak to our RMXP project to have it read the scripts externally.  



Setting up RPG Maker

Make a new folder in the directory of your game, and name it "MyScripts" or whatever you want. In this folder, you can save all the custom scripts your project uses, just save them all with an .rb extension to denote that they are Ruby scripts.  This can be done multiple ways, just copy-paste the script into Notepad++, select "Save As..." and select "Ruby FIle", and set the directory to this folder.

Spoiler: ShowHide


Once done, we need only add a few lines of code to our project.  Either in "Main" before the "begin", or in a separate slot just above it, add these few lines of code:

DIRECTORY = ''
SCRIPTS = [  ]
SCRIPTS.each {|script| require "#{Dir.getwd}/#{DIRECTORY}/#{script}" }


Due to RMVX behaving strangely, you need to explicitly call "require" through the Kernel in it, like this:
DIRECTORY = ''
SCRIPTS = [  ]
SCRIPTS.each {|script| Kernel.require "#{Dir.getwd}/#{DIRECTORY}/#{script}" }


The DIRECTORY value should be the name of the folder you made earlier to contain your scripts, and the SCRIPTS array contains the names of all the scripts to load from that file.  Remove the scripts from the editor and place their filenames into the list in the order that they would be in the script editor.  Here's an example of one filled out for Chronicles of Sir-Lag-a-Lot:

Spoiler: ShowHide


And as you can see, we can now open all the scripts in the Notepad++ editor like this:

Spoiler: ShowHide


This is basically a little "bootstrap" script.  Alternatively you could create a separate Ruby document to this and simply "require" it.  You can now do any scripting you want to these scripts in the Notepad++.  When you press F6 to run the game, these scripts will be read and used for your game.

Summary: ShowHide

  • Install Notepad++

  • Install NppExec plugin for Notepad++

  • Set command to execute game

  • Create script folder, and export scripts to .rb documents into it

  • Add code snippet to game

  • Run from Notepad++



Also remember that the DEBUG variable will not be defined using this method.  You can fix this yourself by simply adding the line:
$DEBUG = true  # RMXP
$TEST = true  # RMVX

In a script somewhere.
I hope this tutorial was helpful. If there are any questions or you need additional help, feel free to ask.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

G_G


ForeverZer0

Its very easy actually. Set up RMXP the same as above, place all your files in a folder etc, and have them loaded into your Netbeans project.

In the Netbeans "main.rb" file (or whatever you named it), simply have this line:


system(`cmd.exe /c "<FULL PATH TO PROJECT'S GAME.EXE>"`)


Notice that the command is surrounded by a `
That is not a single quotation mark, it is a accent character (the key right above "Tab").
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

ForeverZer0

I found a weird bug when using the "require" method in RMVX.  For some reason you have to explicitly call it through the Kernel.  I don't know how the bindings would be different, but you have to.  I updated the main post with a quick edit to show the difference.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

AngryPacman

Well, I found the bug. You just did everything else.
G_G's a silly boy.

Xuroth

Well, I followed your advice. I set-up N++ correctly. I removed the scripts from my game. I pasted them into a folder called IDE Script Data and I added their filenames to the snippet. unfortunately, whether I use N++ or RMXP to Test Play, as soon as I try to display a message (Show Text Event Command) I get the following error:


Script 'Game_Temp' line0:NoMethodError Occurred.
undefined method '<' for nil:NilClass

I think it's a problem with your Multiple Message Script, though I'm not sure. Here is my Configuration from the Script Editor (to show scripts used, in their order):

DIRECTORY = 'IDE Script Data'
SCRIPTS = [
'Zer0_CMS',
'Zer0_Advanced_Weather',
'Zer0_CCTS',
'Zer0_Mult_Message_Windows',
'Show_Event_Names',
'Tons_1',
'Tons_2',
'Tons_3',
'Chaos_Rage_Limit_Sys',
'Scene_SoulRage'
]
SCRIPTS.each {|script| require "#{Dir.getwd}/#{DIRECTORY}/#{script}" }

And I'm aware that it violates the Script Order for a couple scripts, but using this order so far has removed errors I otherwise had between other scripts.


ForeverZer0

Upload your project and I'll look at it.

Did you have this problem before using Notepad++ as the editor?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Xuroth

Nope. I had an error with your Multiple Message Windows, but it was a conflict with LiTTleDRAgo's Show Event Name script. re-ordered and voila!

But I've never seen an error on line 0 before...

<DOWNLOAD>(some scripts are yet unconfigured, but should not interfere with messages. after all, it was working alright before changing to N++)
my bad... i forgot to remove unnecessary images. 1.26MB filesize

ForeverZer0

Well, I found the problem. Both Tons and MMW use a global constant named "TOP".  This is a true/false value used in the HUD in Tons, but is a integer value used by MMW. After checking out the stack trace of the error, I followed it back to the @location variable in MMW, which is initialized as the same value as TOP. This can be fixed by doing a search & replace in MMW of the word TOP (make sure "Match Case" is and "Whole Word" are checked).  You can name it pretty much whatever you like (NOT_BOTTOM, lol).
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Xuroth

Great, that fixed it. How did you know where to look? I mean the only info I gathered was something was causing Game_Temp to think it had an error on line 0 (which I assume is it's hidden dependancy on RPG?)

G_G

*wonders why this isn't in the database*





*leaves for someone else to move it* :V

ForeverZer0

Anytime there is an exception, Ruby stores some valuable information in global variables that can be read by catching the Exception.

$! is a copy of the actual Exception, so you can look at it with "p $!.message", etc.
$@ is the stack trace of the exception, basically a small log of method calls leading up to the exception, with the top one being the line that caused the error. The little message that RMXP gives you when an error occurs is just the final line of this.

I just used a very simple edit to Main. right after or before the current "rescue", add these couple lines:
rescue
  p $!, $@


Now whenever an error occurs, it will tell you what line in what file caused it. Its a good starting point to begin debugging. From there I simply insert a few "p some_variable" here and there at different points for different values to see which one is not what it is supposed to be. This lead me to seeing that @location was true, when it should have been a number. From there, you need only to pick on areas that set the value of @location. I started in the initialize method, and saw it was wrong there, which quickly led me to the result that TOP, which it was initialized as, was wrong. Since I could clearly see that TOP was defined correctly in the MMW script, and TOP is kinda a generic name for a variable, I just did some searches through the other scripts for another that defined TOP, which led me to the culprit.  Its kinda a lonf explanation for something somewhat simple once you know how to look for it. Usually you don't need to follow errors back this far, but there are always those evil little ones that will sneak in here and there....
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Xuroth

October 06, 2011, 03:21:45 am #12 Last Edit: October 08, 2011, 12:16:55 pm by Xuroth
'Notepad++ Custom IDE'::line 0 SyntaxError Occurred

*sigh* So I started configuring the scripts. Everything was working great. I saw a couple of your older scripts and decided to add them in. I added your Addon Collection (originally for the pickpocket script, but after finding a separate updated version of Pickpocket, I want to use this for some other cool features) and your updated Pickpocket Script.

after creating their .rb files in the directory, and adding the file names to the array in RMXP, I get another Line 0 error, this time for the IDE Script

Is there a character, file, or size limit here?

ForeverZer0, why does it seem that I always get the error on line 0?


My IDE Script Config: ShowHide

DIRECTORY = 'IDE Script Data'
SCRIPTS = [
'Zer0_CMS',
'Zer0_Advanced_Weather',
'Zer0_CCTS',
'Zer0_Mult_Message_Windows',
'Zer0_Addon',
'Zer0_PickPocket',
'Tons_1',
'Tons_2',
'Tons_3',
'Show_Event_Names',
'Chaos_Rage_Limit_Sys',
'Scene_SoulRage'
]
SCRIPTS.each {|script| require "#{Dir.getwd}/#{DIRECTORY}/#{script}" }

I also tried adding 'p $!, $@' (without the quote) to main (including and excluding the rescue bit) and nothing changes with the error message.

EDIT: I figured it might be your Add-On  Collection and your Pickpocket script conflicting, and I'm partially right. Your Add-On script doesn't want to play nice, so I am going to look for variable/methods and constants that might be shared with other scripts.ask for help.

EDIT2: I can't seem to see the problem, and it occurs each time before my rescue and p $!, $@ commands in main. I have decided that something in your add on collection must be causing the error/conflicting with another script. I know you removed your addon collection, but I used Google to find v2.5 on another site. If you have an updated version or if you could help me to figure this out, I would be very grateful. If you need it, here is a link to my project so you can download it and test it if you would be willing to assist me.

Download 5.78 MB

Xuroth

Also... Is there any kind of limit to using an IDE? Because I attempted to add (i know its ridiculous to have this many custom scripts) game_guy's Item Storage Script and Game.exe crashes (stops responding and Windows tries to 'find a solution') at runtime. I saved the script as .rb in the scripts folder, and added the filename as a string in the script in RMXP. Removing (commenting the line out in the RMXP Script Editor) this script allows the game to run fine.

Adding the script to the normal Script Editor has no problems though... This is a bit odd...