Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

weird method issue

so i have these two methods, the first one works(add_town) and the second doesnt(remove_town). i dont understand since they are basicly the same thing, flipping the same bool a diffrent way. i would really love any andice one could give!

Code:
 

  def self.add_town(town)

    TOWN_COORD[town-1][7] = true  

  end 

  def self.remove_town(town)

    TOWN_COORD[town-1][7] = false

  end
 
[rgss]  def self.add_town(town, boolean=true)
    TOWN_COORD[town-1][7] = boolean
  end
  def self.remove_town(town)
    self.add_town(town, false)
  end
[/rgss]

Done...
 
here is the whole module(please keep in mind this isnt quite ready for release so there might be some dumb comment errors and such)
Code:
 

#==============================================================================

# ** Plague_Map Script

#------------------------------------------------------------------------------

#  Script by            :   Plague180

#  Last Update          :   March 24, 2010

#  Version              :   1

#  Contact Information  :   plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])

#  Contact Information  :   [email=plague180@yahoo.com]plague180@yahoo.com[/email]

#------------------------------------------------------------------------------

# * Version History :

# 29MAR10 - Version 1.0 Testing Release

#------------------------------------------------------------------------------

# module Map_Items

#------------------------------------------------------------------------------

module Map_Items

  # All icons are to be located in your icon folder

 

  # Icon used for the players current location 

  PLAYER_ICON = "player"  

  

  # Icon used for cursor 

  CURSOR = "cursor"    

  

  # Cursor offset type: 

  # 1 = Static Choices(cursor can only go where the player can move)

  # 2 = Free Choice(cursor can freely move)wip

  CURSOR_TYPE = 1  

  

  # Name Styles:

  # 1 = Under the cursor on the town the cursor is on

  # 2 = Help window on top of screen

  # 3 = None

  NAME_STYLE = 2

  

  # Only for type NAME_STYLE 2

  # Number of pixels to move per left(down) or right(up) press

  MOVE_PIXEL = 15

  

  # Only for type NAME_STYLE 2

  # Number of pixels around the icon you can click

  PIXEL_OFFSET = 20

  

  # Opacity of Name Window

  NAME_WINDOW_OPACITY = 180

  

  # Show player icon above town?

  SHOW_PLAYER = true

  

  # Sound effect on move

  MOVE_SE = RPG::AudioFile.new("018-Teleport01", 80)

  

  # Number of the text color you want to use

  # Please note that you only need Window_Base(216) if you want to use a non

  # default color

  TOWN_TEXT_COLOR = 211 

  

  # Turn fog on and off

  FOG_ON = true

  

  # Graphic used for fog, must be in the Graphics/Fogs Folder

  FOG_GRAPHIC = "001-Fog01"

  

  # Fog Opacity

  FOG_OPACITY = 64

  

  # Fog scroll X

  FOG_SX = 1

  

  # Fog Scroll Y

  FOG_SY = 1

  

  # Fog Blending Type(1=Normal, 2=Add, 3=Subtract)

  FOG_BLEND_TYPE = 1 

 

  # Dont touch

  TOWN_COORD = {}  

# Setting Up a New Town

# 1. Assign a starting x coord

# 2. Assign a starting y coord

# 3. Assign what map you want it to go too

# 4. Assign a x coord on the map you will be moving to

# 5. Assign a y coord on the map you will be moving to

# 6. Assign the direction you want the player to face

#     2 = down

#     4 = left

#     6 = right

#     8 = up

# 7. Assign a non default icon if you wish(use nil if not)

# 8. Assign true or false if you want unlocked by default.

# 

# [starting_x, starting_y, map_id, map_x, map_y, direction, custom_icon, unlocked]

#

# E.g TOWN_COORD[1] = [200,200,2,2,2,2,"town3",true]

#

# VERY IMPORTANT: Put the towns in the order you want the game to cycle threw

# them. you dont have to unlock them in order, just insert them in the order

# you plan too have them cycle.

  TOWN_COORD[0] = [100,380,1,8,4,2,"castle",true,"Saar"]        

  TOWN_COORD[1] = [180,300,2,6,2,4,"town1",true,"Really Long Name"] 

  TOWN_COORD[2] = [200,200,3,2,8,2,"castle",true,"That One Place"]        

  TOWN_COORD[3] = [300,195,4,1,2,2,"town3",false,"Ra"]        

  TOWN_COORD[4] = [425,340,5,12,2,6,"town1",true,"[None]"]        

  TOWN_COORD[5] = [450,100,6,2,6,2,"town2",true,"Guess?",]        

  TOWN_COORD[6] = [520,50,7,2,2,8,"town1",true,"Song Bird"]

  

#--------------------------------------------------------------------------

# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!!!!!!!!!!!

#--------------------------------------------------------------------------

  def self.add_town(town)

    TOWN_COORD[town-1][7] = true  

  end 

  def self.remove_town(town)

    TOWN_COORD[town-1][7] = false

  end   

end #module

 
 
I see. So you are modified constants. I strongly suggest you don't do that. I would have something like this instead:

Code:
 

module Map_Items

  @enabled = Hash.new(default)

  def self.add_map(map_id, bool = true)

    @enabled_map_id = bool

  end

  def self.remove_map(map_id)

    self.add_map(map_id, false)

  end

  def self.enabled

    return @enabled

  end

  def self.enabled=(enabled)

    @enabled = enabled

  end

end

Remember that you are going to have to load and save these as well (I threw in the last 2 methods for this) or add an instance in $game_system or something that saves them which will probably be easier.
 
thank you guys so much!!! but it dawned on my after seph's post i could just hard code the switches i want to use for each town, hench removing the bool in question. serous tho thanks for the help!!!!!!!! :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top