W = (window variable) and then I call W where needed.#const_set, #instance_variable_set, and related methods. If a file needs to access these variables, I put required_relative 'Shared' at the start of the file, then load a variable as needed. I'm not only doing this for the window variable, but for quest and media folders as well.require_relative operations. I'm not sure if I can work around this, or if this approach to sharing variables is itself flawed. (Ruby is my first real language and I've been coding for two months now.)05> require_relative 'Shared'
08> module StageArea
12> W = CommonValues::WINDOW
13> STAGES_FOLDER = File.join CommonValues::QUEST_FOLDER, 'Graphics/Stages'
104> end07> require_relative 'Shared'
08> require_relative 'StageArea'
11> module Quest
13> QUEST_FOLDER = File.join '../Quests', 'Original Quest'
14> CHEATS_FOLDER = File.join QUEST_FOLDER, 'Cheats'
15> DATA_FOLDER = File.join QUEST_FOLDER, 'Data'
16> FONTS_FOLDER = File.join QUEST_FOLDER, 'Fonts'
17> GRAPHICS_FOLDER = File.join QUEST_FOLDER, 'Graphics'
18> MUSIC_FOLDER = File.join QUEST_FOLDER, 'Music'
19> SCENES_FOLDER = File.join QUEST_FOLDER, 'Scenes'
20> SCRIPTS_FOLDER = File.join QUEST_FOLDER, 'Scripts'
21> SOUNDS_FOLDER = File.join QUEST_FOLDER, 'Sound Effects'
22> VOICE_FOLDER = File.join QUEST_FOLDER, 'Voice Effects'
24> CommonValues.const_set(:QUEST_FOLDER, QUEST_FOLDER)
48> end15> require 'rubygems'
16> require 'gosu'
20> require_relative 'Shared'
21> require_relative 'Quest'
28> class Main < Gosu::Window
29> def initialize
32> CommonValues.const_set(:WINDOW, self)
33> CommonValues.const_set(:FRAME_RATE, (1000/self.update_interval).round.to_f)
41> end
79> endUser@COMPUTER ~/Game Engine
$ z2e.rb
~/Game Engine/StageArea.rb:12:in <module:StageArea>': uninitialized constant CommonValues::WINDOW (NameError)
from ~/Game Engine/StageArea.rb:8:in <top (required)>'
from ~/Game Engine/Quest.rb:8:in require_relative'
from ~/Game Engine/Quest.rb:8:in <top (required)>'
from ./z2e.rb:21:in require_relative'
from ./z2e.rb:21:in <main>'Main requires Quest, which requires StageArea, which tries to call two variables from CommonValues that are set in Main. Since Main sets these variables before they are ever called, the error must relate to the peculiarities of require_relative. To make sure of this, I placed a binding.pry (pry is an alternative interactive ruby interpreter to irb) on line 11 of StageArea.rb and injected CommonValues.const_set(:WINDOW, "window"). I then successfully called CommonValues::WINDOW and received "window". So it seems the parsing of W = CommonValues::WINDOW happens before CommonValues.const_set(:WINDOW, self) in Main.rb is actually run.Shared.rb for now, instead of spreading them over several files which would have become confusing later anyhow.
require 'gosu/preview', which is a preview of how the interface will look soon- many methods are now on the module level, such as draw_quad, and constructors don't need window arguments anymore.
0xff0000 being solid red and all, 0xff_ff0000 being the invisibly transparent one. Backwards compatibility for that is a big, fun puzzle. One approach would be to make things constructed with the window argument flip all colors internally. %)
0x... and hope to catch everything. If I forgot one place, I wouldn't notice unless I paid lots of attention while test playing. :(
Shared.rb for now and later will be retrieving them from a external file.
Powered by mwForum 2.29.1 © 1999-2013 Markus Wichitill