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.

[Resolved] Waiting, and MACL

I have a problem with a really easy script  :-[...

This is what I have so far, it is to show a location image, fade it in, then fade it out again.

Code:
  def show_location(location)
    @location = location
    @locationsp = Sprite.new
    @locationsp.bitmap = RPG::Cache.area(location + ".png")
    @locationsp.z = 9999
    @locationsp.opacity = 0
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity += 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity += 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity += 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity += 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity += 55
    @locationsp.update
    @wait_count = 20
    @locationsp.opacity -= 55
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity -= 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity -= 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity -= 50
    @locationsp.update
    @wait_count = 4
    @locationsp.opacity = 0
    @locationsp.update
    #@locationsp.dispose
  end

The first error is that it whizzes straight through them without waiting at all, so the player sees nothing. (I tested this by adding p 'test' at the start and finish).

The second error is a strange one. I had to edit out locationsp.dispose as it gets an error with the MACL...

Script MACL line 2762, RGSS error occurred
disposed sprite

Line 2762 is the following:

Code:
  def draw_trick_function_bar(x, y, width, height, function, current, max, 
      start = Color.new(0,0,0), finish = Color.new(0,0,0), 
      back = Color.new(0,0,0))
    # Get Change in Colors
    chred, chblue = finish.red - start.red, finish.blue - start.blue
    chgreen, chalpha = finish.green - start.green, finish.alpha - start.alpha
    # Draw Background
    radius = height / 2
    # Setup Values Array
    values = []
    # Draw Rectangle Center
    fill_rect(x + radius, y, width - height, height, back) 
    # Draws Ends
    (radius + 1).times do |x1|
      # Get Parameter
      t = radius - x1
      # Get Y
      y1 = function.call(radius, t).round
      # Get Height
      h = 2 * y1
      # Draw Line of Back Color at Left Edge
      fill_rect(x + x1, y - y1 + radius, 1, h, back)
      # Draw Line of Back Color at Right Edge
      fill_rect(x + width - x1, y - y1 + radius, 1, h, back)
    end
    # Get Percentage
    percentage = current / max.to_f
    # Return if not a finite number
    return if not percentage.finite?
    # Decrease Width and Height increase x and y
    width -= 4
    height -= 4
    x += 2
    y += 2
    # Get new Radius
    radius = height / 2
    # Get Bar Width
    barwidth = width * percentage
    # Draws Left End
    (radius + 1).times do |x1|
      # Stop if Past Width
      break if x1 > barwidth
      # Get T (Parameter)
      t = radius - x1
      # Get Width Change
      chwidth = x1
      # Get Colors
      red = start.red + chred * chwidth / width
      green = start.green + chgreen * chwidth / width
      blue = start.blue + chblue * chwidth / width
      alpha = start.alpha + chalpha * chwidth / width 
      # Get Y
      y1 = function.call(radius, t).round
      # Push onto Values
      values << y1
      # Get Height
      h = 2 * y1
      # Get Color
      color = Color.new(red, green, blue, alpha) if alpha != 255
      color = Color.new(red, green, blue) if alpha == 255
      # Draw Line
      fill_rect(x + x1, y - y1 + radius, 1, h, color)
    end
    # Run From Radius upto Rectangles End
    (width - height + 1).times do |t|
------->>># Get X1<<<<<<--------------------------------------------- THIS LINE
      x1 = t + radius
      # Break if Past Width
      break if x1 > barwidth
      # Get Width Change
      chwidth = x1
      # Get Colors
      red = start.red + chred * chwidth / width
      green = start.green + chgreen * chwidth / width
      blue = start.blue + chblue * chwidth / width
      alpha = start.alpha + chalpha * chwidth / width
      # Get Color
      color = Color.new(red, green, blue, alpha) if alpha != 255
      color = Color.new(red, green, blue) if alpha == 255
      # Draw Line
      fill_rect(x + x1, y, 1, height, color)
    end
    # Draws Right End
    radius.times do |t|
      # Get X
      x1 = width - radius + t
      # Stop if Past Width
      break if x1 > barwidth
      # Get Width Change
      chwidth = x1
      # Get Colors
      red = start.red + chred * chwidth / width
      green = start.green + chgreen * chwidth / width
      blue = start.blue + chblue * chwidth / width
      alpha = start.alpha + chalpha * chwidth / width 
      # Get Y
      y1 = values[radius-t]
      # Get Height
      h = 2 * y1
      # Get Color
      color = Color.new(red, green, blue, alpha) if alpha != 255
      color = Color.new(red, green, blue) if alpha == 255
      # Draw Line
      fill_rect(x + x1, y - y1 + radius, 1, h, color)
    end
  end

(What's weird is the error is on a commented out line... isn't the RGSS player supposed to ignore lines commented out? Otherwise what's the point?)
 
1) You are doing that a little wrong. It has to happen between frames, not all at once.

Code:
  def show_location(location)
    @location_sprite = Sprite.new
    @location_sprite.bitmap = RPG::Cache.area(location + '.png')
    @location_sprite.z = 9999
    @location_sprite.opacity = 0
    @location_sprite_in = true
    @location_wait_count = 4
  end
  alias_method :sephwyatt_location_scnmap_update, :update
  def update
    sephwyatt_location_scnmap_update
    if @location_sprite != nil
      if @location_wait_count > 0
        @location_wait_count -= 1
        return
      end
      @location_wait_count = 4
      if @location_sprite_in
        if @location_sprite.opacity == 250
          @location_sprite_in = false
          @location_sprite.opacity -= 50
        else
          @location_sprite.opacity += 50
        end
      else
        if @location_sprite.opacity == 0
          @location_sprite.dispose
          @location_sprite = nil
        else
          @location_sprite.opacity -= 50
        end
      end
    end
  end
end

I haven't tried it, but let me know if it doesn't work.

2) No clue
 

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