Edit & Play 2.1

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

Image


Description

Let you edit and play your game at the same time

Compability

RPG Maker XP and RPG Maker VX

Script

  1. #===============================================================================
  2. # * Edit & Play
  3. #-------------------------------------------------------------------------------
  4. #   - Version: 2.1
  5. #   - Date   : 14 / 08 / 2011
  6. #   - Author : .:Fênix:.
  7. #   - MSN    : [email hidden]
  8. #-------------------------------------------------------------------------------
  9. #   - Description:
  10. #     Let you edit and play your game at the same time
  11. #-------------------------------------------------------------------------------
  12. #   - Compability:
  13. #     RPG Maker XP and RPG Maker VX
  14. #===============================================================================
  15.  
  16. module Edit_and_Play
  17.   # Activate the script? (true / false)
  18.   Activate = true
  19.   # Key which updates the game
  20.   Update_Key = Input::ALT
  21.   # Data files that won't be reloaded
  22.   File_Exclude = []
  23.   # Scripts that won't be reloaded
  24.   Scripts_Exclude = ["Edit & Play", "Main"]
  25. end
  26.  
  27. $VX ||= defined?(Graphics.wait)
  28.  
  29. if ((Edit_and_Play::Activate) && !(File.file?("Game.rgss#{$VX ? '2a' : 'ad'}")))
  30.  
  31.   char     = $VX ? "v" : "x"
  32.   old_file = "Data/BT_Actors.r#{char}data"
  33.   new_file = "Data/BT_Actors2.r#{char}data"
  34.  
  35.   if ($TEST || $DEBUG)
  36.     File.rename(old_file, new_file) if ($BTEST)
  37.     Thread.new {system("Game.exe")}
  38.     exit
  39.   else
  40.     $TEST = $DEBUG = true
  41.     if (File.file?(new_file))
  42.       File.rename(new_file, old_file)
  43.       $BTEST = true
  44.     end
  45.   end
  46.  
  47.   unless ($VX)
  48.     class Scene_Battle
  49.      
  50.       alias :edit_and_play_1 :main unless ($@)
  51.      
  52.       def main
  53.         edit_and_play_1
  54.         $scene = Scene_Battle.new if ($BTEST)
  55.       end
  56.      
  57.     end
  58.   end
  59.  
  60.   class << Input
  61.    
  62.     alias :edit_and_play_2 :update unless ($@)
  63.    
  64.     def update
  65.       if (trigger?(Edit_and_Play::Update_Key))
  66.         for file in (Dir.entries("Data") - [".", "..", *Edit_and_Play::File_Exclude])
  67.           next if (file.include?("Map"))
  68.           basename = File.basename(file, ".*").downcase!
  69.           if (basename == "scripts")
  70.             ($VX ? Cache : RPG::Cache).clear
  71.             for data in load_data("Data/#{file}")
  72.               next if (Edit_and_Play::Scripts_Exclude.include?(data[1]))
  73.               eval(Zlib::Inflate.inflate(data[2]))
  74.             end
  75.             $game_map.setup($game_map.map_id) if ($game_map != nil && $game_map.map_id != 0)
  76.             $scene = $scene.class.new
  77.           else
  78.             eval("$data_#{basename} = load_data('Data/#{file}')")
  79.           end
  80.         end        
  81.       end
  82.       edit_and_play_2
  83.     end
  84.    
  85.   end
  86.  
  87. end
Expand to see the code.


Instructions

Put the script above Main, with the title: Edit & Play
The rest of the instructions are inside of the code.
Wow, this is interesting. I saw the first version, which was good. What's new in this one?
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 🙂)
Awesome! This will save a lot of time!
Wow, it's so nice !!!
I'll add this script to my collection !!! :heart:
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 Main script name's Main, 'cause I started a Dummy Project just to test it.
@MarioSuperStar: Yeah, you're right. I'm fixing it.

Fixed! Edit & Play 2.1 launched!
Please read the new instructions.
This has got to be one of the most useful scripts I've seen out there, definitely going to come in handy for my work. Thanks Fenix!
I've got an issue there:

*The battler sprites of the actors/enemies do not change when I refresh it while Battle Testing it.
@MarioSuperStar I've tested it now, and it has worked here. Make sure you're saving, not just pressing "OK" or "Apply".
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.

Quote:
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
Wow, I think you've got something fantastic here. Brilliant idea and immensely useful.
@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:. wrote:
@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. ;-;
@game_guy I've stopped with RPG maker for a long time. But now I'm back, making some random scripts and helping people. :D

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75377