Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Edit & Play 2.1

Edit & Play 2.1
by .:Fênix:.

enp2.png


Description

Let you edit and play your game at the same time

Compability

RPG Maker XP and RPG Maker VX

Script

Code:
#===============================================================================

# * Edit & Play

#-------------------------------------------------------------------------------

#   - Version: 2.1

#   - Date   : 14 / 08 / 2011

#   - Author : .:Fênix:.

#   - MSN    : [email=bmotamer@hotmail.com]bmotamer@hotmail.com[/email]

#-------------------------------------------------------------------------------

#   - Description:

#     Let you edit and play your game at the same time

#-------------------------------------------------------------------------------

#   - Compability:

#     RPG Maker XP and RPG Maker VX

#===============================================================================

 

module Edit_and_Play

  # Activate the script? (true / false)

  Activate = true

  # Key which updates the game

  Update_Key = Input::ALT

  # Data files that won't be reloaded

  File_Exclude = []

  # Scripts that won't be reloaded

  Scripts_Exclude = ["Edit & Play", "Main"]

end

 

$VX ||= defined?(Graphics.wait)

 

if ((Edit_and_Play::Activate) && !(File.file?("Game.rgss#{$VX ? '2a' : 'ad'}")))

  

  char     = $VX ? "v" : "x"

  old_file = "Data/BT_Actors.r#{char}data"

  new_file = "Data/BT_Actors2.r#{char}data"

  

  if ($TEST || $DEBUG)

    File.rename(old_file, new_file) if ($BTEST)

    Thread.new {system("Game.exe")}

    exit

  else

    $TEST = $DEBUG = true

    if (File.file?(new_file))

      File.rename(new_file, old_file)

      $BTEST = true

    end

  end

  

  unless ($VX)

    class Scene_Battle

      

      alias :edit_and_play_1 :main unless ($@)

      

      def main

        edit_and_play_1

        $scene = Scene_Battle.new if ($BTEST)

      end

      

    end

  end

  

  class << Input

    

    alias :edit_and_play_2 :update unless ($@)

    

    def update

      if (trigger?(Edit_and_Play::Update_Key))

        for file in (Dir.entries("Data") - [".", "..", *Edit_and_Play::File_Exclude])

          next if (file.include?("Map"))

          basename = File.basename(file, ".*").downcase!

          if (basename == "scripts")

            ($VX ? Cache : RPG::Cache).clear

            for data in load_data("Data/#{file}")

              next if (Edit_and_Play::Scripts_Exclude.include?(data[1]))

              eval(Zlib::Inflate.inflate(data[2]))

            end

            $game_map.setup($game_map.map_id) if ($game_map != nil && $game_map.map_id != 0)

            $scene = $scene.class.new

          else

            eval("$data_#{basename} = load_data('Data/#{file}')")

          end

        end        

      end

      edit_and_play_2

    end

    

  end

  

end

Instructions

Put the script above Main, with the title: Edit & Play
The rest of the instructions are inside of the code.
 
Now graphics are reloaded automatically (when you press the Update_Key) and scripts can be reloaded also (if you want, of course. You can change it in the module :smile:)
 
Very nice add-on. It really works!
It is a real time-saver, especially
while debugging. Haven't found any bugs so far.

EDIT: When I press the PlayTest Button to start testing, the game window appears twice and the window hides behind the Editor Window.

Also, when I want to make a Battle Test, the game passes to the Title Screen instead of the Battle Scene.
 
@MarioSuperStar: the first thing is supposed to happen.

But the second thing isn't. Check if the name of the Main script is Main. If it isn't, change it to Main or just change to the title you're using there: Scripts_Exclude = ["Edit & Play", "Main"]
If you don't want to reload scripts, set File_Exclude as ["Scripts.rxdata", "Scripts.rvdata"]

Thank you all. :D
 
The only problem with this is reloading the scripts. I actually figured out a similar method you did when reloading scripts. But its flawed. If you have scripts that have aliased methods you're going to get a stack overflow error. Here's a quote from what Blizzard told me.

Reloading the scripts can cause unexpected errors. One of the first cases that would come to my mind would be the F12 reset bug fix. The $game variable is set the first time and when you run all scripts a second time, the variable would cause the script to abort right at the beginning. As you said, it's not impossible to do, but generally it's a bad idea. You would need a special script to "reset" the state of the Ruby VM before you eval all scripts again. This cannot be automated as it depends on the scripts you are using.

Also, when you re-eval all scripts, you have to keep in mind that all these classes already exist. Your old definitions would be overwritten and the aliasing applied afterwards can cause even more expected behavior, especially in classes/modules that are not yours. If you alias e.g. Input#update once, then a second run would alias it another time with the same name and actually just cause the whole thing to turn into an infinite recursive loop. Using safety precautions everywhere such as "if defined?()" is not much of a option either as you would have to yet again edit all the scripts.

However, everything else is just pretty amazing. Reloads resources and data instantly. Genius. :3
 
@game_guy That's why I always put unless ($@) condition when I alias some method. ;D

And oh well, if you're having problems with scripts reloading, just set File_Exclude as ["Scripts.rxdata", "Scripts.rvdata"].
Thanks again. :D
 
this looks really awesome man!

A really great idea, I haven't actually tried it yet but once I get the chance I will definitely download this! (and probably use it, thoroughly.)
 
.:Fênix:.":1w1nabtj said:
@game_guy That's why I always put unless ($@) condition when I alias some method. ;D

And oh well, if you're having problems with scripts reloading, just set File_Exclude as ["Scripts.rxdata", "Scripts.rvdata"].
Thanks again. :D

True, but if someone has tons of custom scripts, and most scripts I see don't always check if aliases are defined, then the creator would have to edit all those scripts which isn't bad but still a hassle. BTW when I saw this script I wanted to start playing with RMXP again. ;-;
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top