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.

Mining Script I made Wierd duplicate item problem.

Ok my problem with this script is that I just can't seem to figure out why its giving me two of every item. Here is the script and the example:
Code:
#===============================================================================
#
# Mining exp conversion to lvl is taken place and stored here.
# * Purpose of this class is to convert the number(exp) stored in Variable 1,
# ** into a 'Level' system, for example, '5 exp = Level 1'. '10 exp = Level 2'. 
# ** Also, this 'Level' will be stored in a instance variable, and will be
# ** called in other scripts using @mining = Mining_Level_Storage.new().
# ** then the level will be called by saying @mining.level .
#===============================================================================
class Mining_Level_Storage
  
  def initialize
    mining
  end
  
  def mining
    if $game_variables[1] <= 5
      @gvml = 1
    elsif $game_variables[1] <= 10
      @gvml = 2
    elsif $game_variables[1] <= 15
      @gvml = 3
    elsif $game_variables[1] <= 20
      @gvml = 4
    elsif $game_variables[1] <= 25
      @gvml = 5
    elsif $game_variables[1] <= 30
      @gvml = 6
    elsif $game_variables[1] <= 35
      @gvml = 7
    elsif $game_variables[1] <= 40
      @gvml = 8
    elsif $game_variables[1] <= 45
      @gvml = 9
    elsif $game_variables[1] <= 50
      @gvml = 10
    elsif $game_variables[1] <= 55
      @gvml = 11
    end
    @level = @gvml
    level
  end
  
  def level
    return @level
  end

end
#===============================================================================
#
# Mining Process and Chance will be Stored Here.
# * Purpose of this class is to store 'Chance' into my 'Mining' Process. By 
# ** that I mean: Checking by your current Variable => Level, you have a certain
# ** chance that you will recieve an 'Ore'.
# ** Also, it will soon start checking which 'Pik Axe' the user holds, better 
# ** 'Pik Axe' the better the chance.
#===============================================================================
class Event_Mining_Tools
  
  def initialize
    level_check
  end
# Mining Level will be checked here for validation and location.
  def level_check
    @mining = Mining_Level_Storage.new
    if @mining.level <= 5
      $game_party.gain_item(2,1)
    else @mining.level <= 10
      print "2"
    end
  end
  
end
#===============================================================================
#
# Mining Ore Event Starts Here
# * This is what the 'In-Game Event' will call, considering which 'Vein' is 
# ** being mined.
#===============================================================================
class Event_Mining_Ore
  
  def initialize
    stage_one
  end
      
  def stage_one
    if $game_party.item_number(1) >= 1
      @level = Event_Mining_Tools.new()
      @level.level_check
    else
      #$game_temp.message_text = "You need a pick" #<- Not Stopping.
      print "you need a pik"
    end
  end
  
end

Here is where the problem is at:
Code:
  def level_check
    @mining = Mining_Level_Storage.new
    if @mining.level <= 5
      $game_party.gain_item(2,1) # Here
    else @mining.level <= 10
      print "2"
    end
  end

and here is the example, where $game_party.gain_item(2,1) is at, if i were to put 'print "Hello", I would get:
Hello
Hello
and im getting two items of item number 2 even though it clearly shows one, like it is being called twice, don't know why :(.

calling it like this if it helps:
Code:
Event_Mining_Ore.new
 
Looks to me you create a new instance of Event_Mining_Tools, its running level_check for the initialization, but then you are running it again in the following line, if you would observe.

@level = Event_Mining_Tools.new() <--- first case

class Event_Mining_Tools

def initialize
level_check <---- first case
end

@level.level_check <--- second case

Therefore it is my guess it is actually running it twice =P

So try taking out the second call to it.
 
Code:
    if $game_variables[1] <= 5
      @gvml = 1
    elsif $game_variables[1] <= 10
      @gvml = 2
    elsif $game_variables[1] <= 15
      @gvml = 3
    elsif $game_variables[1] <= 20
      @gvml = 4
    elsif $game_variables[1] <= 25
      @gvml = 5
    elsif $game_variables[1] <= 30
      @gvml = 6
    elsif $game_variables[1] <= 35
      @gvml = 7
    elsif $game_variables[1] <= 40
      @gvml = 8
    elsif $game_variables[1] <= 45
      @gvml = 9
    elsif $game_variables[1] <= 50
      @gvml = 10
    elsif $game_variables[1] <= 55
      @gvml = 11
    end
can be replaced by:
Code:
@gvml = ($game_variables[1] / 5).ceil
 

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