The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Parkallooza on January 07, 2009, 01:03:23 PM

Title: Help with changing a reference through Call Script command
Post by: Parkallooza on January 07, 2009, 01:03:23 PM
Okay, since today's a snowday for me, I've been trying my hand at RGSS to pass the time. I've been working at a window to show the objective in the menu, and it works fine, but I want to know how to make the objective changeable using the Call Script command. I've tried nearly everything I could think of, but nothing has worked.

Here's the script:

#==============================================================================
# ** Window_Objective
#------------------------------------------------------------------------------
#  This window displays the party's current objective.
#==============================================================================

  OBJECTIVE = "Make this script work!"

class Window_Objective < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(0, -20, 100, 70, "Objective:")
    self.contents.font.color = normal_color
    self.contents.draw_text(90, -20, 400, 70, OBJECTIVE)
  end
end


It's probably something stupidly simple I'm missing and/or doing wrong, but since I know very little about RGSS, I have no idea what it could be.
Title: Re: Help with changing a reference through Call Script command
Post by: Shinami on January 08, 2009, 10:29:52 PM
I'm not a fan of global variables but this is one case you might try using one. To keep the name of the variable from being an issue, you could try naming it something like $parkallooza_objective. Then just use the Call Script command to change the contents of your global variable.

The same thing may work with public variables as well. Public variables are @variable_types.
Title: Re: Help with changing a reference through Call Script command
Post by: modern algebra on January 08, 2009, 11:47:32 PM
Yeah, I would suggest something similar. I would edit one of the Game_ classes such as Game_System like so:


class Game_System
  attr_accessor :current_objective
  alias prklza_init_obj_var_98n3 initialize
  def initialize
    prklza_init_obj_var_98n3
    @current_objective = "Make this script work!"
  end
end


and then I would just draw $game_system.current_objective in your window. You could change it with a call script: $game_system.current_objective = "". I wouln't put it in it's own global variable because then you'd have to edit Scene_Save and Scene_Load to ensure it is properly saved and loaded. Aside from which, it's a good idea not to have too many global variables floating around.
Title: Re: Help with changing a reference through Call Script command
Post by: Shinami on January 08, 2009, 11:58:01 PM
Thank you for the added knowledge MA. I haven't done scripting in about 6 months or so...so yea, I'm rusty. Modern's idea is much more efficient so I suggest using it.
Title: Re: Help with changing a reference through Call Script command
Post by: Parkallooza on January 09, 2009, 01:40:48 PM
Thanks, mates! I think I tried something like that before, but maybe I did it wrong... Oh well, I'm at school so I'll try it out when I get home. Thanks again!