じ☆ve冰风 发表于 2026-8-2 20:27:38

Editing scripts without leaving the game

Editing scripts without leaving the game​

Hello guys! All right with you?

Today I'm bringing a script called Scene_ResqueReload that I created for use in my projects that are in RPG Maker VX Ace .

The Reason

Unlike many scripts that add new functionality to the game, this script is used as a tool that facilitates the real-time testing of code editing in RPG Maker VX Ace.

Often you need to have a quick response if the changed code is working. It gets more and more stressful when an error occurs in the script and you need several clicks on the tool to open the editor, edit the code, save changes and restart the game.

I have always found limiting the use of the integrated text editor that RPG Maker makes available for code change as there are a wide variety of text editors that provide various tools to help us at that time.

I really enjoy using Sublime Text to program, it has several shortcuts, search engines and numerous text editing tools.

Other text editors can easily be found on the web, whether they are paid, free and even open source. Using this script, you will be able to use the text editor of your choice, be it Sublime, VIM, Atom, Notepad ++, Visual Studio Code, etc ...

Theory

Basically, when the game is started, the script reads a directory within your RPG Maker project and loads the external
files Ruby (.rb) into the game.

By default, the script is set to read the "Scripts" folder of your project's root directory, this folder does not exists by default, so you need to manually create and place your .rb files inside it.

Since we are reading an external file, it is possible to reload the code without closing the game by simply pressing the "F5" key on your keyboard when you are playing the game.

This allows you to change the code in your editor and see the change in your game without closing the game!

The Practice

To use the script, just create the "Scripts" folder within the root directory of your Maker project and create your custom script (.rb) files.



https://i.imgur.com/v9ufw75.png

---

https://i.imgur.com/QGZ1O59.png


After performing the above step, you need to open open the Standard RPG Maker Text Editor and add the script Resque_Reload to the last line.


https://i.imgur.com/Agedkzi.png


Ready! The next time that you open the game, all .rb files in the "Scripts" directory will be read automatically.

The Benefits

Besides using any editor, the script allows you to use version control tools like (Git, CVS, Subversion, Mercurial, etc ...), in case your computer explodes or your game gets corrupted, you will have all your code in a safe place.

Also, whenever you receive a code error, your game no will no longer be closed after this message appears:


https://i.imgur.com/HkNCaCh.png


Now the error message will appear on the Debug screen, with much more information about the error, and your game will automatically go to the home screen (you can see it in the video below)


https://i.imgur.com/MSDm384.png


The Code

The script allows some settings to be changed on its first lines:

- Reading Folder Name:
The default name is "Scripts" but can be changed to any other name (as long as the folder has the same name.)

- Reload key:
By default the F5 button reloads the game in real time, but this key can be changed to one of your own.

Below is the source code of the script and its latest version on Github, plus a video demonstrating how the script works, where I make several changes to a script, changing the displayed name, positioning and causing errors:

If in doubt, I'll always be here, thanks!!

https://github.com/rogesson/RGSSScr...11645bdce2b419dc1d5e5565a2/Scene_ResqueReload



https://www.youtube.com/embed/0U8TE9uoQ1k


Terms

Script Name: Resque Reload
Autor: Resque
Email: rogessonb@gmail.com
Engine: RPG Maker VX
Created At: 13/08/2019
Official Source Code Repository: https://github.com/rogesson/RGSSScr...11645bdce2b419dc1d5e5565a2/Scene_ResqueReload

This script is allowed for commercial and non-commercial games.
Feel free to use it, don't need to credit me in your game.

If you want to share, you must link this post to ensure there are no out of date versions floating around the internet.

                Code:       
# Name: Resque Reload
# Autor: Resque
# Email: rogessonb@gmail.com
# Engine: RPG Maker VX
# Created At: 13/08/2019
# Official Source Code Repository: https://github.com/rogesson/RGSSScripts/tree/ba0b7ef4fdfa8611645bdce2b419dc1d5e5565a2/Scene_ResqueReload

# Script is allowed for commercial and non-commercial games.
# Do not remove this script's credits or header.

class Scene_Base
RELOAD_BUTTON = :F5
SCRIPT_PATH = "Scripts"
FULL_PATH = "#{File.expand_path(Dir.pwd)}/#{SCRIPT_PATH}/*.rb"

DEBUG_MODE = true

def main
    start
    post_start
    update until scene_changing?
    pre_terminate
    terminate

rescue Exception => e
    reload_with_error(e)
end
def update
    update_basic

    reload if Input.trigger?(RELOAD_BUTTON)
end

def reload
    puts "Reload Button [#{RELOAD_BUTTON}] was pressed"
    puts "Reloading the Code..."
    Scene_Base.load_files

    call_current_scene

    nil
end

def self.load_files
    puts "Loading Files..."
    dirs = Dir
    failed = []

    dirs.each do |dir|
      Dir.each do |file|
      begin
          class_name = file.split("/").last

          autoload class_name, file
          load(file)
          puts "#{class_name} Loaded" if Scene_Base::DEBUG_MODE
      rescue NameError => e
          failed << { class_name: class_name, file: file }
          next
      end
      end
    end

    self.retry_failed_files(failed)
    puts "Load completed"
end

def reload_with_error(e)
    error_message(e)
    SceneManager.call(Scene_Title)
end

private

    def self.retry_failed_files(failed_files)
      failed_files.each do |f|
      autoload f[:class_name], f[:file]
      load(f[:file])
      puts "#{f[:class_name]} Loaded" if Scene_Base::DEBUG_MODE
      end
    end

    def error_message(e)
      puts "-----------------------\nERROR: #{e} \n-> #{e.backtrace}\n-----------------------"
    end

    def call_current_scene
      puts "#{self.class} Reloaded"
      SceneManager.call(self.class)
    end
end

Scene_Base.load_files




本贴来自国际rpgmaker官方论坛作者:Resque处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/editing-scripts-without-leaving-the-game.112186/
页: [1]
查看完整版本: Editing scripts without leaving the game