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.

Getting the event's name

Chap

Member

Hi,

I have a question. When I try to get the name of an event, I get an error, while I'm pretty sure the variable exists. I use this line:
Code:
$game_map.events[i].name
(i is an iteration, that shouldn't be the problem.)

Why doesn't this work? :(

T.I.A.

,- Chap
 

Zeriab

Sponsor

It does not work because there is no .name method in Game_Event.
Paste this code somewhere above main in the script editor:
Code:
class Game_Event
  def name
    return @event.name
  end
end

*hugs*
- Zeriab
 

Zeriab

Sponsor

The reason is that there is no method for retrieving the name in Game_Event although there is on in RPG::Event.
What you did wrong was trying to call a method that did not exist.
 

Zeriab

Sponsor

attr_reader generates a method for you. Less code, more readable code. Bonus while the generated code can fulfill your needs.

In this case it would not have work because the generated code would not have been able to retrieve the name.
Why? Because we had to return the name using @event.name and not @name.

Btw. why Bait Question[/b]?
 
Ah, that's right. The Game_Event class has a RPG::Event object as a parameter... 
which has "attr_accessor : name".  could we "attr_accessor :event"  ?

Bait, because I thought I knew the answer, but was asking for the OPs benefit. (and anyone else reading along)

Be Well
 

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