Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Game_Map questions, Not sure where this goes
Adrien.
post Jul 5 2011, 11:51 PM
Post #1


Bet Mapper
Group Icon

Group: Banned
Posts: 1,632
Type: Mapper
RM Skill: Advanced




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]


__________________________



Games I am working on | Each image is a link to the game
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Jul 6 2011, 05:59 AM
Post #2


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




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


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 04:07 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker