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.

Script problems... again...

Sorry for the indescriptive title, but I don't think if I'd written 'Beacon Script problems', you wouldn't been informed better ^_^

Anyway, I tried to make a Beacon script... and as it's the first time somebody attempts this (AFAIK), I'll explain it's purpose shortly:
Events on the map marked with a 'Beacon' comment have an opacity of 0 until the player comes near them. Depending on how close the main character gets, the opacity raises and becomes 255 if the player is above the object. If he gets further away, the opacity decreases again. Of course, this should work with multiple objects on a map simultaneously.

Well, that's the theory... my tries to get this thing to work ended like this:

PHP:
class Beacon
  #--------------------------------------------------------------------------
  attr_accessor :character
  #--------------------------------------------------------------------------
  def initialize(character=nil)
    @character = character
  end
  #--------------------------------------------------------------------------
  def main
    # checks for the comments inside the event
    if (character.is_a?(Game_Event) and character.list!=nil and
      character.list[0].code == 108 and 
      character.list[0].parameters == ["Beacon"])
      # checks for distance between player and event
      d=Math.sqrt(dx.abs**2+dy.abs**2)
      # changes the event's opacity relative to the distance
      character.opacity = [255-d*80,0].max
    end
  end
  #--------------------------------------------------------------------------
end

This is the first version which doesn't brings up any errors, but the events simply don't care about the script ^_^. I commented the 'action' lines for you guys so you can see what I was trying to do, but I have no clue how to go on from here... help would be very apprechiated... :D

Thanks in advance
 
As far as I can see, that script doesn't change the opacity stepless, just between 0 and 250 (should be 255), and I don't think that'd be easy with in_rage? checking... It also wouldn't work because there is no checking for the 'Beacon' string, but that'd be an easy thing to di, I guess...
 
BlueScope said:
As far as I can see, that script doesn't change the opacity stepless, just between 0 and 250 (should be 255), and I don't think that'd be easy with in_rage? checking...
please tell me you are kidding..

BlueScope said:
It also wouldn't work because there is no checking for the 'Beacon' string, but that'd be an easy thing to di, I guess...
ya, but i didn't know you wanted that tho.
 
I'm not kidding... I still think that my way is the best and shortest to do it (the following code)...
Code:
d=Math.sqrt(dx.abs**2+dy.abs**2)
character.opacity = [255-d*80,0].max
... but the rest of the code just didn't work... but the function itself doesn't need a definition for anything, just these two lines of code... while I think that you'd need to check every range individually for the script you posted (I'm not any familiar with it, so I may be wrong...)
 

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