Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] how to have an hook play a sound
@ 2008-01-05 17:11 Giorgio Lando
  2008-01-05 18:43 ` William Morgan
  0 siblings, 1 reply; 3+ messages in thread
From: Giorgio Lando @ 2008-01-05 17:11 UTC (permalink / raw)


Hi again, I do not speak ruby and I am trying to write an after-poll.rb
which plays a sound when there are new messages.
I have tried several things, but probably I am misunderstanding
something radical. I would like that it executes the sound when the
variable @num (the number of polled messages) is >= 1.

My less absurd try is perhaps:

if @num>=1
system "/usr/bin/aplay -q <mysound>"
end

but I get the following error:

Error running hook: undefined method `>=' for nil:NilClass

With:

if @num!=0
system "/usr/bin/aplay -q <mysound>"
end

The sound is always player, also when there is no new message polled.

I have tried to define or declare a class or a method somewhere, but I am really
lost.
Any help?
Giorgio Lando


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] how to have an hook play a sound
  2008-01-05 17:11 [sup-talk] how to have an hook play a sound Giorgio Lando
@ 2008-01-05 18:43 ` William Morgan
  2008-01-05 21:29   ` Giorgio Lando
  0 siblings, 1 reply; 3+ messages in thread
From: William Morgan @ 2008-01-05 18:43 UTC (permalink / raw)


Excerpts from Giorgio Lando's message of Sat Jan 05 09:11:10 -0800 2008:
> Hi again, I do not speak ruby and I am trying to write an
> after-poll.rb which plays a sound when there are new messages.

No problem. You were just one small character away.

> My less absurd try is perhaps:
> 
> if @num>=1
> system "/usr/bin/aplay -q <mysound>"
> end

Just remove the '@'. The variable 'num' is what you want; '@num' refers
to a different, instance, variable. @num is undefined, so it defaults to
'nil', and that's why the error was about an undefined method on the nil
object.

(Incidentally, you can use instance variables to save state between
successive calls to the same hook. Not useful in this case, but in more
complex hooks this is handy.)

> With:
> 
> if @num!=0
> system "/usr/bin/aplay -q <mysound>"
> end
> 
> The sound is always player, also when there is no new message polled.

This is because nil is not equal to 0 in Ruby, so the conditional is
always true.

You can also check out the example hooks on the Wiki
(http://sup.rubyforge.org/wiki/wiki.pl?Hooks). Feel free to post your
masterpiece there when completed.

-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] how to have an hook play a sound
  2008-01-05 18:43 ` William Morgan
@ 2008-01-05 21:29   ` Giorgio Lando
  0 siblings, 0 replies; 3+ messages in thread
From: Giorgio Lando @ 2008-01-05 21:29 UTC (permalink / raw)


> Just remove the '@'. The variable 'num' is what you want; '@num' refers
> to a different, instance, variable. @num is undefined, so it defaults to
> 'nil', and that's why the error was about an undefined method on the nil
> object.
> 
> (Incidentally, you can use instance variables to save state between
> successive calls to the same hook. Not useful in this case, but in more
> complex hooks this is handy.)

Thanks, now it sounds properly. As soon as I write something a bit more
elaborate. I will publish it in the wiki for sure.
Giorgio 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-05 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-05 17:11 [sup-talk] how to have an hook play a sound Giorgio Lando
2008-01-05 18:43 ` William Morgan
2008-01-05 21:29   ` Giorgio Lando

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox