Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

DragonRuby Game Toolkit

An intuitive 2D game engine. Fast, cross-platform, tiny, hot loaded. · By DragonRuby

uninitialized constant when using require

A topic by terinchu created Jul 07, 2020 Views: 870 Replies: 5
This topic is archived. It is unlisted and no new posts can be made.
Viewing posts 1 to 7

Just starting with dragonruby, I'm trying a file structure like this one:

app/main.rb
app/game.rb
app/components/board.rb
app/components/player.rb
app/components/solid.rb
app/components/sprite.rb
app/components/tile.rb

where my main.rb class is like:

require 'app/game.rb'
@game = Game.new
def tick(args) 
  @game.args = args 
  @game.tick
end

and game.rb class is:

require 'app/components/sprite.rb'
require 'app/components/solid.rb'
require 'app/components/player.rb'
require 'app/components/tile.rb'
class Game
  attr_gtk
  attr_accessor :tiles, :player
  def initialize
    @tiles = generate_tiles
    @player = Player.new(0, 0)
  end
  # more code...

Then when I start dragonruby ./ , the app fails with:

2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.264 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.311 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
2020-07-07 22:42:24.311 dragonruby[72992:170603] INFO: NameError: uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed.
* EXCEPTION:
uninitialized constant (class Game (included_modules [AttrGTK]) )::Tile
* ERROR: Invocation of Game.new failed. (0)
* INFO: Exported the current game state to file exceptions/game_state_-1.txt.
* INFO: Marked app/components/sprite.rb for reload. (57)
* INFO: Marked app/components/solid.rb for reload. (57)
* INFO: Marked app/components/player.rb for reload. (57)
* INFO: Marked app/components/tile.rb for reload. (57)

However, if I touch the main.rb class with a save, the console display:

* INFO: Marked app/main.rb for reload. (897)

then the game loads correctly.

What I'm missing here?

DragonRuby isn't easy to debug. What's the code for `generate_tiles` ?

I wonder if you have a legit "uninitialized constant" but somehow DragonRuby's hot reloading is able to skip past it?

the workaround wisdom at the moment is put all your requires in main.rb; not ideal, but it seems to work

Hello there. First post here. 

 I'm trying to get my head around DragonRuby. Thanks for the suggestion @phasefx. Issue is, I generally use TDD with Ruby, but that approach doesn't help with unit testing ( unless  more ugly workarounds like `defined?($gtk)`, etc ... ) .

It would be really great if DragonRuby allowed `require` / `require_relative` like n the rest of the ruby community. IMHO if DragonRuby manages to do this, it can leverage open source & modularity to improve DragonRuby ecosystem, and therefore create "exponential" value for its users. 

   

@terinchu. After some testing I realized that after object creation ( aka initialize method) the require's tend to work. 

Developer

Take a look at this structure: https://itch.io/post/3307721

Developer archived this topic