Skip to content

Instantly share code, notes, and snippets.

@pulsejet
Last active May 5, 2018 06:33
Show Gist options
  • Save pulsejet/bbaf3f043ffee1146174159cae042f74 to your computer and use it in GitHub Desktop.
Save pulsejet/bbaf3f043ffee1146174159cae042f74 to your computer and use it in GitHub Desktop.
Guide for mkxp with mruby

mkxp + mruby = ❤

RGSS Script Changes

Language differences

Replace all instances of

begin
    statement
end until condition

with

loop do
  statement
  break if condition
end

Regex

Watch out for getting the first character with a different syntax i.e. text.slice!(0)

Saving

Use this for write_save_data after removing any prior Marshal.dump instances

data = {
    "characters": 		characters,
    "frame_count": 		Graphics.frame_count,
    "$game_system":		$game_system,
    "$game_switches":		$game_switches,
    "$game_variables":		$game_variables,
    "$game_self_switches":	$game_self_switches,
    "$game_screen":		$game_screen,
    "$game_actors":		$game_actors,
    "$game_party":		$game_party,
    "$game_troop":		$game_troop,
    "$game_map":		$game_map,
    "$game_player":		$game_player
}
Marshal.dump(data, file)

For load,

data = Marshal.load(file.read)
$game_system        = data[:"$game_system"]
$game_switches      = data[:"$game_switches"]
$game_variables     = data[:"$game_variables"]
$game_self_switches = data[:"$game_self_switches"]
$game_screen        = data[:"$game_screen"]
$game_actors        = data[:"$game_actors"]
$game_party         = data[:"$game_party"]
$game_troop         = data[:"$game_troop"]
$game_map           = data[:"$game_map"]
$game_player        = data[:"$game_player"]

and in Window_SaveFile

@characters = data[:"characters"]
@frame_count = data[:"frame_count"]
@game_system = data[:"$game_system"]
@game_switches = data[:"$game_switches"]
@game_variables = data[:"$game_variables"]

Monkey Patching

Avoid. Any calls to super from an aliased method that has been monkey patched will try to call a method with the aliased name.

Compiling mruby

Use mruby-onig-regexp and mruby-marshal, along with this patch. Make sure cc.defines = %w(MRB_INTEGER_DIVISION) and cxx.defines = %w(MRB_INTEGER_DIVISION) are both present in your build_config.rb

Emscripten

For building with emscripten, you need to take out any main loops. This is done by adding a new method in Main as

$prev_scene = nil

def main_update_loop
  if $scene != nil
    if $scene != $prev_scene
      if $prev_scene != nil
	$prev_scene.dispose
      end
      $scene.main
      $prev_scene = $scene
    end
    # Update game screen
    Graphics.update
    # Update input information
    Input.update
    # Frame update
    $scene.update
  else
    raise "END"
  end
end

Then remove any infinite loop in any RGSS scene's main method and add a method dispose to every scene which esentially does everything that is supposed to be done after the loop breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment