librelist archives

« back to archive

dragons&direwolves - issues

dragons&direwolves - issues

From:
Sebastjan Hribar
Date:
2013-03-13 @ 07:50
Hi,

I've ran into a puzzling issues with this project.

1.
If you take a look at the dd.rb line 108 and 151 at
https://github.com/sebastjan-hribar/summoner_chronicles/blob/master/dd.rb

you'll see they're basically the same, however 108 passes but 151 causes
the app to crash with this error:

**********************************************************************
dd.rb:151:in `block (3 levels) in battle': undefined method `each' for
nil:NilClass
**********************************************************************

I can't find the reason. Is it because the second instance is in a new
url/method and slot? But shouldn't the instance variable take care of
that?

I thought I wasn't using the instance/class variables and the module
reference in the right way, but I checked in a small test app and
everything worked when referenced like in the dd.rb.


2.
How can I use the @hm_deck as items in a listbox?

I'd like the names of the objects in the @hm_deck as items of the
listbox:


@card = list_box items: [@hm_deck.each {|c| c.name}]

I get the same error about NilClass as above.


regards,
seba



 

Re: [shoes] dragons&direwolves - issues

From:
Jesús Gabriel y Galán
Date:
2013-03-13 @ 08:15
On Wed, Mar 13, 2013 at 8:50 AM, Sebastjan Hribar
<sebastjan.hribar@gmail.com> wrote:
> Hi,
>
> I've ran into a puzzling issues with this project.
>
> 1.
> If you take a look at the dd.rb line 108 and 151 at
> https://github.com/sebastjan-hribar/summoner_chronicles/blob/master/dd.rb
>
> you'll see they're basically the same, however 108 passes but 151 causes
> the app to crash with this error:
>
> **********************************************************************
> dd.rb:151:in `block (3 levels) in battle': undefined method `each' for
> nil:NilClass
> **********************************************************************
>
> I can't find the reason. Is it because the second instance is in a new
> url/method and slot? But shouldn't the instance variable take care of
> that?
>
> I thought I wasn't using the instance/class variables and the module
> reference in the right way, but I checked in a small test app and
> everything worked when referenced like in the dd.rb.

It's been a while since I used Shoes, but IIRC, when you visit a URL,
a new object is created, and so instance variables refer to a
different object. You can check printing self and self.object_id at
the points you want to check, to verify if it's the same object.

> 2.
> How can I use the @hm_deck as items in a listbox?
>
> I'd like the names of the objects in the @hm_deck as items of the
> listbox:
>
>
> @card = list_box items: [@hm_deck.each {|c| c.name}]
>
> I get the same error about NilClass as above.

I think the problem is the same as above. When you use @hm_deck there,
you are in a different object, where that instance variable has not
been initialized. Check which object is self at each point.

Regarding how to pass info from one URL to another, there are several
ways. Looking around in google I've seen an answer from _why himself
about either using class variables (@@hm_deck), a constant or an
external storage such as sqlite or a file.

Let's see if more knowledgeable people answer, because, as I said I
haven't done anything with shoes in a while, and I don't know if
things have changed.

Jesus.

Re: [shoes] dragons&direwolves - issues

From:
Sebastjan Hribar
Date:
2013-03-17 @ 06:22
Hi,

I've finished porting the existing code to green shoes and now the next
step is some shoe polishing:)

1.
In the dd.rb in the battle section (lines 139-165) I have cards
displayed from the player's deck. Additionally I'd like the card / or
the Summon button, @a or @b, respectively, removed once it's been used.

What happens is that no matter which card is used, the last one in the
deck is removed for the first time any of the cards are clicked. I
imagine because @a or @b is the last card / button rendered. How might i
achieve that the right card / button is removed when used?

2.
The cards get rendered but with small position deviation. The first card
is placed a bit higher than the rest in the flow. How to fix this?

------------------------------------

Note: I still have to implement some "clicked?" checks for other
buttons, arrange the records display and polish the GUI in general, but
for now the game should work.


kind regards

love shoes!
seba 

Re: [shoes] dragons&direwolves - issues

From:
J. Kaiden
Date:
2013-03-17 @ 15:40
hi Seba,

  one possible solution for your first question is to make a card widget -
something like this:

require 'green_shoes'

class Card < Shoes::Widget
def initialize(color)
s = stack margin: 3, width: 150, height: 200 do
 background color; border black
button "Select" do
s.clear
 end
end
end
end

Shoes.app do
 c1 = card(red)
c2 = card(blue)
c3 = card(green)
 end


  the game looks cool - looking forward to playing it...

  shoes on,

  j


On Sun, Mar 17, 2013 at 7:22 AM, Sebastjan Hribar <
sebastjan.hribar@gmail.com> wrote:

> Hi,
>
> I've finished porting the existing code to green shoes and now the next
> step is some shoe polishing:)
>
> 1.
> In the dd.rb in the battle section (lines 139-165) I have cards
> displayed from the player's deck. Additionally I'd like the card / or
> the Summon button, @a or @b, respectively, removed once it's been used.
>
> What happens is that no matter which card is used, the last one in the
> deck is removed for the first time any of the cards are clicked. I
> imagine because @a or @b is the last card / button rendered. How might i
> achieve that the right card / button is removed when used?
>
> 2.
> The cards get rendered but with small position deviation. The first card
> is placed a bit higher than the rest in the flow. How to fix this?
>
> ------------------------------------
>
> Note: I still have to implement some "clicked?" checks for other
> buttons, arrange the records display and polish the GUI in general, but
> for now the game should work.
>
>
> kind regards
>
> love shoes!
> seba
>
>

Re: [shoes] dragons&direwolves - issues

From:
ashbb
Date:
2013-03-19 @ 13:04
Hi Seba,

Sorry for my late reply.

1st issue:
How about using an array instead of an instance variable?

2nd issue:
Umm,... may be a bug...
Could you add one more flow?

Try out the following code reflecting the above workarounds.

  flow margin: 5 do
    flow margin_left: 5 do
      a = []
      @@hm_deck.each_with_index {|c,i|
        a[i] = stack margin: 3, width: 150, height: 200 do
            if c.subtype == "dragon"
              background blue
              border black, strokewidth: 2
            elsif c.subtype == "dire wolf"
              background red
              border black, strokewidth: 2
            elsif c.subtype == "healing spell"
              background antiquewhite
              border black, strokewidth: 2
            else

            end
            para "#{i+1}. #{c.name}\n#{c.subtype}\n#{c.
attributes}"
            #gumb za izbiro
            button "Select" do
              @hm_card = c
              a[i].clear
            end
        end
      }
    end
  end

Cheers,
ashbb

Re: [shoes] dragons&direwolves - issues

From:
Sebastjan Hribar
Date:
2013-03-19 @ 20:02
Hi ashbb,

the code below solved both issues.

Thank you and kind regards,
seba

Dne 19.03.2013 (tor) ob 22:04 +0900 je ashbb napisal(a):
> Hi Seba,
> 
> Sorry for my late reply.
> 
> 1st issue:
> How about using an array instead of an instance variable?
> 
> 2nd issue:
> Umm,... may be a bug...
> Could you add one more flow?
> 
> Try out the following code reflecting the above workarounds.
> 
>   flow margin: 5 do
>     flow margin_left: 5 do
>       a = []
>       @@hm_deck.each_with_index {|c,i|
>         a[i] = stack margin: 3, width: 150, height: 200 do
>             if c.subtype == "dragon"
>               background blue
>               border black, strokewidth: 2
>             elsif c.subtype == "dire wolf"
>               background red
>               border black, strokewidth: 2
>             elsif c.subtype == "healing spell"
>               background antiquewhite
>               border black, strokewidth: 2
>             else
> 
>             end
>             para "#{i+1}. #{c.name}\n#{c.subtype}\n#{c.
> attributes}"
>             #gumb za izbiro
>             button "Select" do
>               @hm_card = c
>               a[i].clear
>             end
>         end
>       }
>     end
>   end
> 
> Cheers,
> ashbb
> 
> 

Re: [shoes] dragons&direwolves - issues

From:
Sebastjan Hribar
Date:
2013-03-19 @ 20:01
Hi Jake,

thank you for this suggestion. To be honest this was my first encounter
with a widget so I followed your example and I defined it in the module:

      #Card
      class Card < Shoes::Widget
        def initialize(color, c, i, test)
          s = stack margin: 3, width: 150, height: 200 do
            background color; border black
            para "#{i+1}. #{c.name}\n#{c.subtype}\n#{c.attributes}"
            b = button "Summon" do
            @hm_card = c
            b.clear
            end
          end
        end
      end


and then called it in the main file:

             flow margin: 5 do

                @@hm_deck.each_with_index {|c,i|
                      if c.subtype == "dragon"
                        color = "royalblue"
                      elsif c.subtype == "dire wolf"
                        color = "forestgreen"
                      elsif c.subtype == "healing spell"
                        color = "violet"
                      else
                      end
                   card = card(color, c, i)
                }
              end


Cards were displayed nicely and everything worked,
but I struggled yet again with the variable scope for @hm_card as it
didn't go beyond the widget object.

For now I am using the version from ashbb, but I am not through with
widgets:)

kind regards
seba

Dne 17.03.2013 (ned) ob 16:40 +0100 je J. Kaiden napisal(a):
> hi Seba,
> 
> 
>   one possible solution for your first question is to make a card
> widget - something like this:
> 
> 
> require 'green_shoes'
>  
> class Card < Shoes::Widget
> def initialize(color)
> s = stack margin: 3, width: 150, height: 200 do
> background color; border black
> button "Select" do
> s.clear
> end
> end
> end
> end
> 
> 
> Shoes.app do
> 
> c1 = card(red)
> c2 = card(blue)
> c3 = card(green)
> 
> end
> 
> 
> 
> 
>   the game looks cool - looking forward to playing it...
> 
> 
>   shoes on,
> 
> 
>   j
> 
> 
> On Sun, Mar 17, 2013 at 7:22 AM, Sebastjan Hribar
> <sebastjan.hribar@gmail.com> wrote:
>         Hi,
>         
>         I've finished porting the existing code to green shoes and now
>         the next
>         step is some shoe polishing:)
>         
>         1.
>         In the dd.rb in the battle section (lines 139-165) I have
>         cards
>         displayed from the player's deck. Additionally I'd like the
>         card / or
>         the Summon button, @a or @b, respectively, removed once it's
>         been used.
>         
>         What happens is that no matter which card is used, the last
>         one in the
>         deck is removed for the first time any of the cards are
>         clicked. I
>         imagine because @a or @b is the last card / button rendered.
>         How might i
>         achieve that the right card / button is removed when used?
>         
>         2.
>         The cards get rendered but with small position deviation. The
>         first card
>         is placed a bit higher than the rest in the flow. How to fix
>         this?
>         
>         ------------------------------------
>         
>         Note: I still have to implement some "clicked?" checks for
>         other
>         buttons, arrange the records display and polish the GUI in
>         general, but
>         for now the game should work.
>         
>         
>         kind regards
>         
>         love shoes!
>         seba
>         
> 
>