Forum: Ruby Gosu "Name error" problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dd4a3018f3ba74d275b8dd01cef5967f?d=identicon&s=25 Zsolnai Csaba (kanesoban)
on 2009-03-13 00:16
Attachment: Gosu.rb (1 KB)
Hello

I'm trying to write a program, that hopefully will turn into a simple
strategy game sometime. For now, i've got to the point, where a new game
window shows up.

Now i wrote a method that should draw a rectangle when you hold down the
left mouse button, and move the mouse (like in any rts game, so that you
can select multiple units).  Now, this method obviously does not work,
and i'm not sure why.
If somebody could look at my code (its 1 page), and tell me the problem,
i would be grateful. However, i'm using the 'gosu' module, so it is
needed to run this program. I attached the code to this message.
B0081fbf12827173517cd9457fc37523?d=identicon&s=25 julian^screenfashion (aka survivor) (Guest)
on 2009-03-13 02:21
(Received via mailing list)
Hello Zsolnai,

It looks like you mixed up Gosu's interfaces for C++ and Ruby :) In
Ruby, it is simply draw_quad (vs. graphics().drawQuad), or
Window#draw_quad to be more precise.
Also, the last argument should be :default instead of Gosu::amDefault.
You can leave it out, though.

The complete Ruby interface can be found at:
http://code.google.com/p/gosu/wiki/RubyReference

More information and a forum dedicated to only Gosu can be found on
http://www.libgosu.org/.

Regards,
Julian
Dd4a3018f3ba74d275b8dd01cef5967f?d=identicon&s=25 Zsolnai Csaba (kanesoban)
on 2009-03-15 14:01
Thank you. Replacing Gosu::Graphics:drawQuad with just draw_quad solved
the problem. What i don't understand, is why draw_quad works, and
Gosu::Graphics::draw_quad doesn't ?
B0081fbf12827173517cd9457fc37523?d=identicon&s=25 julian^screenfashion (aka survivor) (Guest)
on 2009-03-16 17:36
(Received via mailing list)
> What i don't understand, is why draw_quad works, andGosu::Graphics::draw_quad doesn't ?

Basically, because there is no Graphics class at all in the Ruby
version of Gosu, where all the methods from Graphics have been moved
to the Window class. Also, draw_quad is a *method*;
Gosu::Graphics::draw_quad() would be a call to a *class method* of
Gosu::Graphics. So there's only Gosu::Window#draw_quad, and you'd call
it on an instance of Window, or without any instance at all in the
methods of your Window.

Regards,
Julian
This topic is locked and can not be replied to.