Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: P6: OO Wizard Game (RPG kinda, sorta)

by Juerd (Abbot)
on May 13, 2005 at 12:57 UTC ( [id://456706]=note: print w/replies, xml ) Need Help??


in reply to P6: OO Wizard Game (RPG kinda, sorta)

I think that

when 'f' { say "You ran away from the $enemy.name()!" } if ($.weapons.exists($_)) { .attack($enemy, $.weapons{$_}); } else { say "Please enter a valid command!" }
Is much prettier when written as
when 'f' { say "You ran away from the { $enemy.name }!" } when $.weapons { .attack($enemy, $.weapons{$_}); } default { say "Please enter a valid command!" }
"when" combined with "if"/"else" just doesn't feel right. It's better style to write %.weapons, by the way. (Why would $.weapons even work? It's not declared!)

Note that my comments are not tested against the reality of Pugs.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: P6: OO Wizard Game (RPG kinda, sorta)
by dragonchild (Archbishop) on May 13, 2005 at 13:00 UTC
    Don't you have to say .attack($enemy, %.weapons{$_}); }? $.weapons doesn't exist, only %.weapons does.

    • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
    • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

      Don't you have to say .attack($enemy, %.weapons{$_}); }?

      Yes.

        Well you don't have to in the current Pugs....So is that a bug then? Or something that is currently undefined? It is hard to tell often which is mostly why I started this thread.


        ___________
        Eric Hodges
Re^2: P6: OO Wizard Game (RPG kinda, sorta)
by eric256 (Parson) on May 13, 2005 at 13:11 UTC

    The if isn't all that ugly ;). Either way the code you suggested doesn't work yet. I didn't even know that smart matching would do a hash key lookup...or what yours suppose to do? On the $ versus % note, I have updated my code with that, once I get some more updates I will probably recommit it.


    ___________
    Eric Hodges

      I didn't even know that smart matching would do a hash key lookup

      See S04. Hash ~~ Any has no *, so it is reversible: Any ~~ Hash.

      I have updated my code with that, once I get some more updates I will probably recommit it.

      Why wait?

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://456706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found