in reply to Daft text adventure project
Several comments:
- It's a bit late, since you've obviously already put a lot of work into it, but I'd suggest you look at what other MUD and text-adventure authors are doing now. Text adventures have come a long way since Infocom. Check out the rec.arts.int-fiction newsgroup http://www.faqs.org/faqs/games/interactive-fiction/authoring/part1/ , and look at the engines at http://directory.google.com/Top/Games/Video_Games/Genres/Adventure/Text_Adventures/Design_and_Development/Authoring_Systems/ (Inform and TADS are arguably the two most used systems. Inform is probably the most powerful, with TADS having an easier interface while still being flexible) (the main IF archive can be reached at http://www.ifarchive.org/
- You mention that references confuse you. No problem. Here's my attempt to explain them, which differs from the typical "It's a pointer" explanation.
- References are Scalars
- Perl has a few data types, the most common of which are lists, hashes, and scalars. A reference is a scalar. It "refers" to any data type. This is advantagious, because it allows you to put a non-scalar data type where you would normally store a scalar.
For example, A hash is a collection of scalars. You can't make $foo{Bar} hold a hash, but you can make it hold a reference to a hash. This means you can have nested data types.
Let's try a simple example for your program. Let's just say that you wanted to have multiple characters. You could have %characters hold them, with their name as the key, so that $characters{'Bob the Fighter'} would hold Bob's info. What is Bob's info? well, he'll have Attributes, Feats, Skills, Level, and so forth. Each of those could be a hash storing more detailed info. Let's initialize a sample:
To access some of Bob's data, we de-reference the reference with the arrow operator: $character{'Bob the Fighter'}->{'Attributes'}->{'Str'} would equal 10.$characters{'Bob the Fighter'} = { #The brackets create a reference t +o an anonymous hash. 'Attributes' => { # We're nesting a second hash 'Str' => 10, 'Dex' => 10 }, #Done with that hash 'Level' => 1, #Storing a normal scalar 'Feats' => { #Another hash! 'Light_Armor' => 1 #Treating as a boolean } #done with Feats Hash }; #done with hash that is stored in $characters{'Bob the Fighter' +}References are key to any complicated data manipulation in Perl. I suggest experimenting.
In Section
Seekers of Perl Wisdom