Forum: Ruby Some error for Tk.

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.
A1b97dafea62b11e7b3bef338ce3fe83?d=identicon&s=25 CFC (Guest)
on 2006-02-19 17:12
(Received via mailing list)
Hi.
When I was running my program, and click the button, it will show the
following message:
ArgumentError: wrong number of arguments (1 for 0)

But, I have been read some samples..

and here is my code:

require 'tk'
require 'sdl'

def Play(path, times)
  music=SDL::Mixer::Music.load(path)
  SDL::Mixer.playMusic(music,-1)
end
SDL::init(SDL::INIT_AUDIO)
SDL::Mixer.open
path=TkVariable.new
TkEntry.new("textvariable"=>path).pack("padx"=>10)
TkButton.new(){
  text "Play"
  command {proc Play(path.value, -1)}
}.pack("padx"=>10)
Tk.mainloop

Does it have any error in the code?
Could anyone help me?
Thank you a lot.
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-02-19 17:16
(Received via mailing list)
DÅ?a Nedeľa 19 Február 2006 17:08 CFC napísal:
> Hi.
> When I was running my program, and click the button, it will show the
> following message:
> ArgumentError: wrong number of arguments (1 for 0)
>

You botched something or the API changed a bit since the samples were
made.
What line / in which method call? It's hard to put the finger on this
without
that for people that don't know Tk and SDL by heart without that.

David Vallner
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-02-19 17:22
(Received via mailing list)
Follow up after skimming the code a few times, by lucky coincidence, I
actually remember THAT much Tk...

DÅ?a Nedeľa 19 Február 2006 17:08 CFC napísal:
> TkEntry.new("textvariable"=>path).pack("padx"=>10)
> TkButton.new(){
>   text "Play"
>   command {proc Play(path.value, -1)}

IIRC, the #command method takes a Proc object as an argument, not a
block. The
above line should most probably be:
	command(proc { Play(path.value, -1) })

You or someone else misplaced a curly brace, I added the parentheses for
clarity.

> }.pack("padx"=>10)
> Tk.mainloop
>

(Why the heck is the #Play method in CamelCase anyway? Tsk-tsk-tsk, the
sample
author should get a lecture about naming conventions.)

David Vallnerr
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-02-20 10:56
(Received via mailing list)
From: David Vallner <david@vallner.net>
Subject: Re: Some error for Tk.
Date: Mon, 20 Feb 2006 01:21:20 +0900
Message-ID: <200602191721.01248.david@vallner.net>
> IIRC, the #command method takes a Proc object as an argument, not a block. The
> above line should most probably be:
> 	command(proc { Play(path.value, -1) })

A block is available for #command method on current Ruby/Tk.
So,

      command { Play(path.value, -1) }

is acceptable.
A1b97dafea62b11e7b3bef338ce3fe83?d=identicon&s=25 CFC (Guest)
on 2006-03-08 11:14
(Received via mailing list)
Thanks a lot. :D
I've been solve this problem.
Thanks again!!
This topic is locked and can not be replied to.