librelist archives

« back to archive

Custom Methods in Shoes

Custom Methods in Shoes

From:
Jim Hendi
Date:
2012-01-30 @ 13:40
    

Hello, I'm a total noob at shoes and I'm having a bit of trouble. 


Basically I want to make a little calculator but I can't get shoes to 
display the result of my methods calculations. For example:

Shoes.app do

  def calc(v1, v2)
   v1 + v2
  end

  line1 = edit_line
  line2 = edit_line

  button 'Compute' do
  para = calc(line1, line2)
end
end

 Doesn't work, neither does any combination of that general idea I've 
tried. I know I'm missing something simple. If anyone can point me in the 
right direction I would be grateful! 


Cheers,

Facetoe

Re: [shoes] Custom Methods in Shoes

From:
Maximilian Stroh
Date:
2012-01-30 @ 13:45
To get the content of an input field, use the text() method... In your case
remember that the value of an editline is always a string, so to_i could be
useful.
Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:

>
> Hello, I'm a total noob at shoes and I'm having a bit of trouble.
>
> Basically I want to make a little calculator but I can't get shoes to
> display the result of my methods calculations. For example:
>
> Shoes.app do
>
>   def calc(v1, v2)
>    v1 + v2
>   end
>
>   line1 = edit_line
>   line2 = edit_line
>
>   button 'Compute' do
>   para = calc(line1, line2)
> end
> end
>  Doesn't work, neither does any combination of that general idea I've
> tried. I know I'm missing something simple. If anyone can point me in the
> right direction I would be grateful!
>
> Cheers,
>
> Facetoe
>
>

Re: [shoes] Custom Methods in Shoes

From:
Jim Hendi
Date:
2012-01-30 @ 14:10
Thanks for your response, but I'm still having trouble...

I tried this but it doesn't work:

Shoes.app do 
  def calc(v1, v2)
  v1.to_i  +  v2.to_i
  end
  line1 = edit_line.text
  line2 = edit_line.text
  button 'Compute' do
    @result = calc(line1, line2)
  end
  para @result
end

When I press the 'Compute' button I getthis error in the console - 
undefined method 'to_i' for (Shoes::EditLine.

If I get rid of the 'to_i' then it changes to - undefined method + for 
(Shoes::EditLine.

Any ideas?







________________________________
 From: Maximilian Stroh <hisako1337@googlemail.com>
To: shoes@librelist.org 
Sent: Monday, 30 January 2012 9:45 PM
Subject: Re: [shoes] Custom Methods in Shoes
 

To get the content of an input field, use the text() method... In your 
case remember that the value of an editline is always a string, so to_i 
could be useful.
Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:

    
>
>Hello, I'm a total noob at shoes and I'm having a bit of trouble. 
>
>
>
>Basically I want to make a little calculator but I can't get shoes to 
display the result of my methods calculations. For example:
>
>
>Shoes.app do
>
>
>  def calc(v1, v2)
>   v1 + v2
>  end
>
>
>  line1 = edit_line
>  line2 = edit_line
>
>
>  button 'Compute' do
>  para = calc(line1,
 line2)
>end
>end
>
> Doesn't work, neither does any combination of that general idea I've 
tried. I know I'm missing something simple. If anyone can point me in the 
right direction I would be grateful! 
>
>
>
>Cheers,
>
>
>Facetoe
>
>
>

Re: [shoes] Custom Methods in Shoes

From:
Jenna Fox
Date:
2012-01-30 @ 14:34
Simple - you're assigning line1 and line2 to the contents of 
edit_line.text when the window was created, not the contents of those 
inputs when the Compute button was pressed. Since the boxes were empty 
when created, your strings line1 and line2 are empty, and when to_i are 
called on those strings, no number can be found. You'll need to get rid of
.text on both those lines, and add .text to the @result = calc(line1, 
line2). You'll also need a way to update the text in your results 
paragraph

One way to redo your program to work would be this:

Shoes.app do  
  def calc(v1, v2)
    v1.to_i  +  v2.to_i
  end
  line1 = edit_line
  line2 = edit_line
  button 'Compute' do
    @result.text = calc(line1.text, line2.text)
  end
  @result = para
end

I don't have shoes on this computer and don't have time to test it, so I 
hope this works! Good luck! :)  


—
Jenna Fox


On Tuesday, 31 January 2012 at 1:10 AM, Jim Hendi wrote:

> Thanks for your response, but I'm still having trouble...
>  
> I tried this but it doesn't work:
>  
> Shoes.app do  
>   def calc(v1, v2)
>   v1.to_i  +  v2.to_i
>   end
>   line1 = edit_line.text
>   line2 = edit_line.text
>   button 'Compute' do
>     @result = calc(line1, line2)
>   end
>   para @result
> end
>  
> When I press the 'Compute' button I get this error in the console - 
undefined method 'to_i' for (Shoes::EditLine.
>  
> If I get rid of the 'to_i' then it changes to - undefined method + for 
(Shoes::EditLine.
>  
> Any ideas?
>  
>  
>  
>  
> From: Maximilian Stroh <hisako1337@googlemail.com 
(mailto:hisako1337@googlemail.com)>
> To: shoes@librelist.org (mailto:shoes@librelist.org)  
> Sent: Monday, 30 January 2012 9:45 PM
> Subject: Re: [shoes] Custom Methods in Shoes
>  
> To get the content of an input field, use the text() method... In your 
case remember that the value of an editline is always a string, so to_i 
could be useful.  
> Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com 
(mailto:facetoe@ymail.com)>:
> >      
> > Hello, I'm a total noob at shoes and I'm having a bit of trouble.  
> >  
> > Basically I want to make a little calculator but I can't get shoes to 
display the result of my methods calculations. For example:
> >  
> > Shoes.app do  
> >  
> >   def calc(v1, v2)
> >    v1 + v2
> >   end
> >  
> >   line1 = edit_line
> >   line2 = edit_line
> >  
> >   button 'Compute' do
> >   para = calc(line1, line2)
> > end
> > end
> >  Doesn't work, neither does any combination of that general idea I've 
tried. I know I'm missing something simple. If anyone can point me in the 
right direction I would be grateful!  
> >  
> > Cheers,
> >  
> > Facetoe
> >  
>  
>  

Re: [shoes] Custom Methods in Shoes

From:
Jim Hendi
Date:
2012-01-30 @ 14:42
Thanks you so much Jenna, that makes perfect sense, and even better now it works!




________________________________
 From: Jenna Fox <a@creativepony.com>
To: shoes@librelist.org 
Sent: Monday, 30 January 2012 10:34 PM
Subject: Re: [shoes] Custom Methods in Shoes
 

Simple - you're assigning line1 and line2 to the contents of 
edit_line.text when the window was created, not the contents of those 
inputs when the Compute button was pressed. Since the boxes were empty 
when created, your strings line1 and line2 are empty, and when to_i are 
called on those strings, no number can be found. You'll need to get rid of
.text on both those lines, and add .text to the @result = calc(line1, 
line2). You'll also need a way to update the text in your results 
paragraph

One way to redo your program to work would be this:

Shoes.app do 
  def calc(v1, v2)
    v1.to_i  +  v2.to_i
  end
  line1 = edit_line
  line2 = edit_line
  button 'Compute' do
    @result.text = calc(line1.text, line2.text)
  end
  @result = para
end

I don't have shoes on this computer and don't have time to test it, so I 
hope this works! Good luck! :)



—
Jenna Fox

On Tuesday, 31 January 2012 at 1:10 AM, Jim Hendi wrote:
Thanks for your response, but I'm still having trouble...
>
>
>I tried this but it doesn't work:
>
>
>Shoes.app do 
>  def calc(v1, v2)
>  v1.to_i  +  v2.to_i
>  end
>  line1 = edit_line.text
>  line2 = edit_line.text
>  button 'Compute' do
>    @result = calc(line1, line2)
>  end
>  para @result
>end
>
>
>When I press the 'Compute' button I get this error in the console - 
undefined method 'to_i' for (Shoes::EditLine.
>
>
>If I get rid of the 'to_i' then it changes to - undefined method + for 
(Shoes::EditLine.
>
>
>Any ideas?
>
>
>
>
>
>
>
>
>
>
>________________________________
> From: Maximilian Stroh <hisako1337@googlemail.com>
>To: shoes@librelist.org 
>Sent: Monday, 30 January 2012 9:45 PM
>Subject: Re: [shoes] Custom Methods in Shoes
> 
>
>To get the content of an input field, use the text() method... In your 
case remember that the value of an editline is always a string, so to_i 
could be useful.
>Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:
>
>    
>>
>>Hello, I'm a total noob at shoes and I'm having a bit of trouble. 
>>
>>
>>
>>Basically I want to make a little calculator but I can't get shoes to 
display the result of my methods calculations. For example:
>>
>>
>>Shoes.app do
>>
>>
>>  def calc(v1, v2)
>>   v1 + v2
>>  end
>>
>>
>>  line1 = edit_line
>>  line2 = edit_line
>>
>>
>>  button 'Compute' do
>>  para = calc(line1,
 line2)
>>end
>>end
>>
>> Doesn't work, neither does any combination of that general idea I've 
tried. I know I'm missing something simple. If anyone can point me in the 
right direction I would be grateful! 
>>
>>
>>
>>Cheers,
>>
>>
>>Facetoe
>>
>>
>>
>
> 

Re: [shoes] Custom Methods in Shoes

From:
Maximilian Stroh
Date:
2012-01-30 @ 15:55
Shoes.app do
#lines
@para = para ""
Button "compute" do
  result = line1.to_i + line2.to_i
  @para.text = result.to_s
End

You have to use the text() method to get/set the values of the ui elements
:-)
Am 30.01.2012 15:11 schrieb "Jim Hendi" <facetoe@ymail.com>:

> Thanks for your response, but I'm still having trouble...
>
> I tried this but it doesn't work:
>
> Shoes.app do
>   def calc(v1, v2)
>   v1.to_i  +  v2.to_i
>   end
>   line1 = edit_line.text
>   line2 = edit_line.text
>   button 'Compute' do
>     @result = calc(line1, line2)
>   end
>   para @result
> end
>
> When I press the 'Compute' button I get this error in the console -
> undefined method 'to_i' for (Shoes::EditLine.
>
> If I get rid of the 'to_i' then it changes to - undefined method + for
> (Shoes::EditLine.
>
> Any ideas?
>
>
>
>
>   ------------------------------
> *From:* Maximilian Stroh <hisako1337@googlemail.com>
> *To:* shoes@librelist.org
> *Sent:* Monday, 30 January 2012 9:45 PM
> *Subject:* Re: [shoes] Custom Methods in Shoes
>
> To get the content of an input field, use the text() method... In your
> case remember that the value of an editline is always a string, so to_i
> could be useful.
> Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:
>
>
> Hello, I'm a total noob at shoes and I'm having a bit of trouble.
>
> Basically I want to make a little calculator but I can't get shoes to
> display the result of my methods calculations. For example:
>
> Shoes.app do
>
>   def calc(v1, v2)
>    v1 + v2
>   end
>
>   line1 = edit_line
>   line2 = edit_line
>
>   button 'Compute' do
>   para = calc(line1, line2)
> end
> end
>  Doesn't work, neither does any combination of that general idea I've
> tried. I know I'm missing something simple. If anyone can point me in the
> right direction I would be grateful!
>
> Cheers,
>
> Facetoe
>
>
>
>

Re: [shoes] Custom Methods in Shoes

From:
James
Date:
2012-01-30 @ 14:25
Sounds like a type issue. Is there a safe intermediary type you can
use to go from Shoes::Editline to an integer? Maybe string?




On Mon, Jan 30, 2012 at 7:10 AM, Jim Hendi <facetoe@ymail.com> wrote:
> Thanks for your response, but I'm still having trouble...
>
> I tried this but it doesn't work:
>
> Shoes.app do
>   def calc(v1, v2)
>   v1.to_i  +  v2.to_i
>   end
>   line1 = edit_line.text
>   line2 = edit_line.text
>   button 'Compute' do
>     @result = calc(line1, line2)
>   end
>   para @result
> end
>
> When I press the 'Compute' button I get this error in the console -
> undefined method 'to_i' for (Shoes::EditLine.
>
> If I get rid of the 'to_i' then it changes to - undefined method + for
> (Shoes::EditLine.
>
> Any ideas?
>
>
>
>
> ________________________________
> From: Maximilian Stroh <hisako1337@googlemail.com>
> To: shoes@librelist.org
> Sent: Monday, 30 January 2012 9:45 PM
> Subject: Re: [shoes] Custom Methods in Shoes
>
> To get the content of an input field, use the text() method... In your case
> remember that the value of an editline is always a string, so to_i could be
> useful.
> Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:
>
>
> Hello, I'm a total noob at shoes and I'm having a bit of trouble.
>
> Basically I want to make a little calculator but I can't get shoes to
> display the result of my methods calculations. For example:
>
> Shoes.app do
>
>   def calc(v1, v2)
>    v1 + v2
>   end
>
>   line1 = edit_line
>   line2 = edit_line
>
>   button 'Compute' do
>   para = calc(line1, line2)
> end
> end
>  Doesn't work, neither does any combination of that general idea I've tried.
> I know I'm missing something simple. If anyone can point me in the right
> direction I would be grateful!
>
> Cheers,
>
> Facetoe
>
>
>

Re: [shoes] Custom Methods in Shoes

From:
Jim Hendi
Date:
2012-01-30 @ 14:40

I'm not sure if this is what you meant (I'm noob) but I tried this:

Shoes.app do 
  def calc(v1, v2)
  v1.to_s.to_i + v2.to_s.to_i
  end
  line1 = edit_line.text
  line2 = edit_line.text
  button 'Compute' do
    @result = calc(line1, line2)
  end
  para @result
end

Strangely, it stopped the errors but the result is still not displayed. 







________________________________
 From: James <oscartheduck@gmail.com>
To: shoes@librelist.org 
Sent: Monday, 30 January 2012 10:25 PM
Subject: Re: [shoes] Custom Methods in Shoes
 
Sounds like a type issue. Is there a safe intermediary type you can
use to go from Shoes::Editline to an integer? Maybe string?




On Mon, Jan 30, 2012 at 7:10 AM, Jim Hendi <facetoe@ymail.com> wrote:
> Thanks for your response, but I'm still having trouble...
>
> I tried this but it doesn't work:
>
> Shoes.app do
>   def calc(v1, v2)
>   v1.to_i  +  v2.to_i
>   end
>   line1 = edit_line.text
>   line2 = edit_line.text
>   button 'Compute' do
>     @result = calc(line1, line2)
>   end
>   para @result
> end
>
> When I press the 'Compute' button I get this error in the console -
> undefined method 'to_i' for (Shoes::EditLine.
>
> If I get rid of the 'to_i' then it changes to - undefined method + for
> (Shoes::EditLine.
>
> Any ideas?
>
>
>
>
> ________________________________
> From: Maximilian Stroh <hisako1337@googlemail.com>
> To: shoes@librelist.org
> Sent: Monday, 30 January 2012 9:45 PM
> Subject: Re: [shoes] Custom Methods in Shoes
>
> To get the content of an input field, use the text() method... In your case
> remember that the value of an editline is always a string, so to_i could be
> useful.
> Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:
>
>
> Hello, I'm a total noob at shoes and I'm having a bit of trouble.
>
> Basically I want to make a little calculator but I can't get shoes to
> display the result of my methods calculations. For example:
>
> Shoes.app do
>
>   def calc(v1, v2)
>    v1 + v2
>   end
>
>   line1 = edit_line
>   line2 = edit_line
>
>   button 'Compute' do
>   para = calc(line1, line2)
> end
> end
>  Doesn't work, neither does any combination of that general idea I've tried.
> I know I'm missing something simple. If anyone can point me in the right
> direction I would be grateful!
>
> Cheers,
>
> Facetoe
>
>
>

Re: [shoes] Custom Methods in Shoes

From:
J. Kaiden
Date:
2012-01-30 @ 14:43
Hi there -

  try this -

Shoes.app do
def calc(v1, v2)
v1 + v2
 end

line1 = edit_line
line2 = edit_line
button 'Compute' do
@result = calc(line1.text.to_i, line2.text.to_i)
para @result
end
end

  you don't have to call .to_s on the edit_line.text - it's already a
string - but you do then have to convert it to an integer with .to_i

 hth -

  - j



On Mon, Jan 30, 2012 at 2:40 PM, Jim Hendi <facetoe@ymail.com> wrote:

>
> I'm not sure if this is what you meant (I'm noob) but I tried this:
>
> Shoes.app do
>   def calc(v1, v2)
>   v1.to_s.to_i + v2.to_s.to_i
>
>   end
>   line1 = edit_line.text
>   line2 = edit_line.text
>   button 'Compute' do
>     @result = calc(line1, line2)
>   end
>   para @result
> end
>
> Strangely, it stopped the errors but the result is still not displayed.
>
>
>
>
>   ------------------------------
> *From:* James <oscartheduck@gmail.com>
> *To:* shoes@librelist.org
> *Sent:* Monday, 30 January 2012 10:25 PM
>
> *Subject:* Re: [shoes] Custom Methods in Shoes
>
> Sounds like a type issue. Is there a safe intermediary type you can
> use to go from Shoes::Editline to an integer? Maybe string?
>
>
>
>
> On Mon, Jan 30, 2012 at 7:10 AM, Jim Hendi <facetoe@ymail.com> wrote:
> > Thanks for your response, but I'm still having trouble...
> >
> > I tried this but it doesn't work:
> >
> > Shoes.app do
> >   def calc(v1, v2)
> >   v1.to_i  +  v2.to_i
> >   end
> >   line1 = edit_line.text
> >   line2 = edit_line.text
> >   button 'Compute' do
> >     @result = calc(line1, line2)
> >   end
> >   para @result
> > end
> >
> > When I press the 'Compute' button I get this error in the console -
> > undefined method 'to_i' for (Shoes::EditLine.
> >
> > If I get rid of the 'to_i' then it changes to - undefined method + for
> > (Shoes::EditLine.
> >
> > Any ideas?
> >
> >
> >
> >
> > ________________________________
> > From: Maximilian Stroh <hisako1337@googlemail.com>
> > To: shoes@librelist.org
> > Sent: Monday, 30 January 2012 9:45 PM
> > Subject: Re: [shoes] Custom Methods in Shoes
> >
> > To get the content of an input field, use the text() method... In your
> case
> > remember that the value of an editline is always a string, so to_i could
> be
> > useful.
> > Am 30.01.2012 14:41 schrieb "Jim Hendi" <facetoe@ymail.com>:
> >
> >
> > Hello, I'm a total noob at shoes and I'm having a bit of trouble.
> >
> > Basically I want to make a little calculator but I can't get shoes to
> > display the result of my methods calculations. For example:
> >
> > Shoes.app do
> >
> >   def calc(v1, v2)
> >    v1 + v2
> >   end
> >
> >   line1 = edit_line
> >   line2 = edit_line
> >
> >   button 'Compute' do
> >   para = calc(line1, line2)
> > end
> > end
> >  Doesn't work, neither does any combination of that general idea I've
> tried.
> > I know I'm missing something simple. If anyone can point me in the right
> > direction I would be grateful!
> >
> > Cheers,
> >
> > Facetoe
> >
> >
> >
>
>
>