Kingdom Ablaze
Sponsor
here is the error i get: "undefined method 'switch' for nil:NilClass" but when you go to my class there it is. the code is duplicate except for a few minor changes, i cant find problem.
this line works:
But this one doesnt:
Here are the classes:
this line works:
Code:
if $game_switches[Map_Items::Towns[@pindex].switch] == true
Code:
if $game_switches[Sub::Towns[@pindex].switch] == true
Code:
module Map_Items
Towns = {}
end
module Sub
Towns = {}
end
class Data::Object
@@ids = {}
@@containers = {}
attr_accessor :id
def initialize
@@ids[self.class] = 0 unless @@ids.has_key?(self.class)
@@ids[self.class] += 1
@id = @@ids[self.class]
if @@containers.has_key?(self.class)
@@containers[self.class][@id] = self
end
end
def self.add_container(class_name, container)
@@containers[class_name] = container
end
end
class Map_Items::Town < Data::Object
Data::Object.add_container(self, Map_Items::Towns)
attr_reader :screen_x
attr_reader :screen_y
attr_reader :map_id
attr_reader :map_x
attr_reader :map_y
attr_reader :direction
attr_reader :icon
attr_reader :town_name
attr_reader :switch
def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon, town_name, switch)
super()
@screen_x = screen_x
@screen_y = screen_y
@map_id = map_id
@map_x = map_x
@map_y = map_y
@direction = direction
@icon = icon
@town_name = town_name
@switch = switch
end
def self.screen_x
return @screen_x
end
def self.screen_y
return @screen_y
end
def self.map_id
return @map_id
end
def self.map_x
return @map_x
end
def self.map_y
return @map_y
end
def self.direction
return @direction
end
def self.icon
return @icon
end
def self.town_name
return @town_name
end
def self.switch
return @switch
end
end
class Sub::Town < Data::Object
Data::Object.add_container(self, Sub::Towns)
attr_reader :upper_level
attr_reader :screen_x
attr_reader :screen_y
attr_reader :map_id
attr_reader :map_x
attr_reader :map_y
attr_reader :direction
attr_reader :icon
attr_reader :town_name
attr_reader :switch
def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon, town_name, switch, upper_level)
super()
@screen_x = screen_x
@screen_y = screen_y
@map_id = map_id
@map_x = map_x
@map_y = map_y
@direction = direction
@icon = icon
@town_name = town_name
@switch = switch
@upper_level = upper_level
end
def self.screen_x
return @screen_x
end
def self.screen_y
return @screen_y
end
def self.map_id
return @map_id
end
def self.map_x
return @map_x
end
def self.map_y
return @map_y
end
def self.direction
return @direction
end
def self.icon
return @icon
end
def self.town_name
return @town_name
end
def self.switch
return @switch
end
def self.upper_level
return @upper_level
end
end