Help - Search - Members - Calendar
Full Version: Game_Map questions
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS2
Adrien.
I have a scripting question in rterms of calling other scripts. For example if I do:

CODE
class Scene_Title < Scene_Base
  
  def initialize
    
    @map_size_w     = Game_Map.width
    
    print @map_size_w
  end
  
end


I get a undefined method width for game_map....

When there is a def width method in the actual class of Game_Map.....

also do I have to do Scene_Title < Scene_Base just to print values out to test? AND how can I do the same $some_method(param) like when you do $game_actors.actorid[1]
Night5h4d3
Game_Map itself refers to the class of Game_Map, a class in Ruby is not automatically initialized 'from the getgo' so to speak.
Each class that is referable has already been created. So, at the beginning of the 'game,' the game classes are created and assigned.
When referring to them, you use the assigned variable, rather than the class itself, so rather than using Game_Map.width, you'd use the variable that initialized it, in this case: $game_map.

Likewise with all other game_ classes; see line 115~125 of the Scene_Title script to see how the variables are assigned.

Secondly, this would not work in the Title scene because that is the scene in which Game_Map is initialized and assigned, you pretty much need to run your code separately after the game has fully loaded (like in a new scene after scene_title, or from the call script event command), yes, it's a hassle, but testing things like this in the title scene is not wise.

thirdly, the parameters, also known as arguments are simple to do, but there's several ways, first way, is simple argument passing:
CODE
class My_Class
  def do_something(n,x,y)
   # do something
  end
end

When you create my class, like @classvar = My_Class.new you can later call do something like so: @classvar.do_something(n,x,y)
I won't go into much detail about the methods, so alternately, it looks like you're wanting to refer to an array, the way that is done is like so:

CODE
class Game_Actors
def [](actor_id)
    return @data[actor_id]
  end
end


Basically what this def is is that it's if Game_Actors is used as an array rather than def or class. this allows you to do functions like so:
$game_actors[n]

And this belongs in RGSS2 Script support, moving ~Night5h4d3
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.