On Thu, Sep 29, 2011 at 8:40 PM, Rob V. <robtvogel / gmail.com> wrote:
> I'm trying to make a card game with Ruby. I created a hash of cards and
> numeric values which works fine on its own:
> example:
> =A0 =A0 deck =3D Hash.new
> =A0 =A0 deck["Ah"] =3D 1
> =A0 =A0 deck["1h"] =3D 1
> =A0 =A0 deck["2h"] =3D 2
> =A0 =A0 deck["3h"] =3D 3
> =A0 =A0 deck["4h"] =3D 4
> =A0 =A0 deck["5h"] =3D 5
> where:
> =A0 =A0 puts deck["3h"]
> properly returns 3.
>
> I wrote some code to output the hash into an array and then shuffle it
> which also works. I have code to deal out the cards into new arrays for
> each player which works as well. My issue is when I try to call things
> like:
>
> =A0 =A0 puts player1.first
> it will give the appropriate first card in the hand but:
>
> =A0 =A0 puts deck[player1.first]
> does not return the value of the card. I've also tried created place
> holder variables without avail:
>
> =A0 =A0 x =3D player1.first
> =A0 =A0 puts x
> gives the proper output of the card in hand but:
>
> =A0 =A0 puts deck[x]
> comes up a blank line.
> Any thoughts?

Can you show a complete example in which we can see the error?
Things to check:
- Are you sure you are putting the keys of the hash in the arrays?
- What does puts player1.first outputs: "Ah" or 1?

Jesus.

Jesus.