Dipseydoodle has asked for the wisdom of the Perl Monks concerning the following question:
Hello perlmonks. I apologize for my lack of knowledge here. I am a hobby programmer, not a professional. I have been writing a MOO (multi user dungeon game) and I am having problems figuring out what I shall do with objects within the game. right now I have a single room with objects. The problem is not making it known to the player that the objects are there but simply how to interact with the objects.
#!/usr/local/bin/perl print"\n"; print "#---#--#-####-#----####-#####---#--#---####\n"; print "-#-##-#--####-#----#----#---#--#-##-#--####\n"; print "--#--#---####-####-####-#####-#---#--#-####\n"; print "\n"; print "|The Lounge|\n"; print "You are in a room littered with lines of text emitting from var +ious computer connections from around the world. Above you hangs a dr +oning chandelier which seems to dim and increase lighting every so of +ten. The pleasant sound of a Jazz-Fusion band is heard here.\n"; print "You can see a wooden table here. You can SIT at the table. You +see a 1970's Jukebox here.\n"; print "You can go OUT.\n";
That's what I have... The objects describes as the Table and Jukebox are what I would like to be able to interact with. The question is what kind of syntax should I use?
I would like something like this sit table = print "You pull up a chair and sit at the table/";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl Moo.
by stevieb (Canon) on Jun 13, 2012 at 15:56 UTC | |
Here's a basic example using a dispatch table-driven menu system:
| [reply] [Watch: Dir/Any] [d/l] |
Re: Perl Moo.
by cavac (Parson) on Jun 13, 2012 at 18:00 UTC | |
I pulled together a small, working mini adevnture. I decided to split the definition of objects and rooms into two different hashes. Objects can also be in a virtual room (like the "inventory" room i use here. But you can also send them into a non-existing room to make them go away or vice versa. The anonymous subs also allow you to change objects and rooms as you wish. For example, a closed door might have an action "open" that rewrites it's own description as well as adding an exit to the room. Closing that door again can do the opposite (return original description, remove the rooms exit) Here's the code:
Of course, you might want to split all the room and object definitions into multiple files.
"You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."
| [reply] [Watch: Dir/Any] [d/l] |
by Dipseydoodle (Acolyte) on Jun 13, 2012 at 19:38 UTC | |
That's slighty more complex then I wanted *takes a look back and screeches* But it's really funny you mentioned Inform7, it happens to be my favored language for gaming (I have released a few games actually) but I wanted a step up, just not this much. Also, Inform7 is awesome, however I need this to be MULTI-USER not single player. Time to look for another route I guess, maybe Python or Ruby? | [reply] [Watch: Dir/Any] |
by cavac (Parson) on Jun 13, 2012 at 20:13 UTC | |
however I need this to be MULTI-USER not single player. Multi-User is always way more complicated, no matter the programming language. You have to share data, allow concurrent access and so on. That said, would a web based solution work for you? If so, you could try a combination of Perl/CGI, HTML/Javascript/Ajax and maybe a database/memcached as data backend.
"You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."
| [reply] [Watch: Dir/Any] |
by Dipseydoodle (Acolyte) on Jun 14, 2012 at 20:25 UTC | |
by cavac (Parson) on Jun 15, 2012 at 21:32 UTC | |
Re: Perl Moo.
by Khen1950fx (Canon) on Jun 13, 2012 at 16:59 UTC | |
| [reply] [Watch: Dir/Any] [d/l] |
by onelesd (Pilgrim) on Jul 12, 2012 at 21:24 UTC | |
Can you explain what Sub::Quote does in Moo? I read the description provided from the Moo doc but I don't understand why inlining is any better than a regular coderef and I'd hate to start using it without knowing why I should be or what it does. SUB QUOTE AWARE "quote_sub" in Sub::Quote allows us to create coderefs that are "inlineable," giving us a handy, XS-free speed boost. Any option that is Sub::Quote aware can take advantage of this. | [reply] [Watch: Dir/Any] |
Re: Perl Moo.
by sundialsvc4 (Abbot) on Jun 13, 2012 at 17:28 UTC | |
> hello sailor While I am absolutely delighted to see an “interactive fiction/MUD” effort starting here, I would cordially suggest that perhaps you should first review the open-source tools that are already out there which are expressly designed for this purpose. They already have vocabulary, parsing, data representation, multiplayer and other concerns well in hand... a big leg-up. The Wikipedia articles on “interactive fiction” and “MUD” (Multi-User Dungeon) are foundation resources. > give all spare time to dungeon game | [reply] [Watch: Dir/Any] |
by cavac (Parson) on Jun 13, 2012 at 18:53 UTC | |
While you are quite right that using a complete, fully functional game engine is a good idea for most projects, you may be overlooking a few crucial points:
Btw, another very good adventure game engine/IDE is Inform7. You basically describe the scenes, objects and interactions in more or less plain english and it "compiles" it into a working text adventure. I must admit, it's not completly to my liking (quite challenging to do some standard stuff). Here's an experiment i cobbled together a few months ago:
Read more... (10 kB)
Not everything in this (rather badly designed) example works as expected, it's quite a mess and some things i did are needlessly complicated. But hey, i am a Perl guy. Explaining something to a computer in plain english lacks style ;-)
"You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."
| [reply] [Watch: Dir/Any] [d/l] |