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.

Fade event script

I tried to make a script that fades an event but I failed. Could someone tell me what I'm doing wrong?

Code:
class Spriteset_Map
  def fade_event(char, duration)
    # sprite_character equal to:
    sprite = @character_sprites.detect {|s| s.character == char }
    # Character opacity duration
    sprite.opacity(duration)
  end
end

class Scene_Map
  attr_reader :spriteset
end

class Interpreter
  # flash_event(index[, color[, duration]])
  #
  # Index: The event that is to fade
  # Duration: The time it takes for sprite to disappear completely
  def fade_event(index, duration=20)
    if $scene.instance_of?(Scene_Map)
      if index != 0
        event = $game_map.events[index]
        if event.nil?
          raise IndexError, "fade_event: Index error"
        end
      else
        event = $game_player
      end
      $scene.spriteset.fade_event(event, duration*2)
    end
  end
end
 
Script 'Fade Event' line 18: SyntaxError occurred.
Hold on, I fixed that.

Now it says:

Code:
Script 'Fade Event' line 10: NoMethodError occurred.

Undefined method '-' for nil:NilClass
 
Well, I worked on this for hours, with little luck. First, I was able to make the event disappear after a few seconds, but not fade. Then, I was able to make every event and the player fade out, and when it all faded, everything went back to normal except the event to be faded. This would work, but only if the event was the only event visible onscreen. Not very handy, no.
I could not figure out why everything faded. Finally, I just stopped and used events. This can go in an event or common event, and you can use either a set number(e.g. 3,17,8) or a variable(e.g. $game_variables[1],$foo) for the event's id. Maybe you can translate this to a script, I dunno.

First put this in Game_Character, or add a new script above main that adds it in.
Code:
  attr_accessor :opacity
Then, use this in an event.
Code:
Loop
Conditional Branch: Script: $game_map.events[3].opacity <= 0
Break Loop
Else
Script: $game_map.events[3].opacity -= 8
Wait: 1 frame(s)
Branch End
Repeat Above
Sorry I couldn't be of much more help! Good luck to you though! :D
 

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