randomized weaponry

Okay… so I have been programming with I7 for a while now; about 3 years. I’m usually too lazy to finish a game, but have gotten a few done…
Enough about me. This is my problem. I am creating a role-playing game… sort of, and have been trying to create a randomized weaponry system. If I could get it working, I could use it for other things, too.

The problem seems to be with the last one (when play begins). The compiler says that there are many ways to do this, and my paragraph does not fit one of them, or something like that. As a side note, forget about the weak, medium and strong stuff, I’ll implement what that does later. Huge thanks in advance!

Hi!

I’m afraid your main problem is going to be using text values for the name and type parts of your weapons. Although Inform allows things to be understood by some values, text values aren’t one of them. This means the player will have no way of referring to individual weapons by name (“get the tiny dagger of punnyness”, etc.). Worse, Inform won’t be able to sort them out, so anytime you’ve got more than one random weapon in a room, you’ll get something like “You see five random weapons here.”

Luckily, this is easy to fix by making each of these properties a new kind of value (which you can still define using tables if you wish). Something like:

[code]“IntFic” by Mike Tarbert

A weapon is a kind of thing. A random weapon is a kind of weapon.

Weapon-type is a kind of value. The weapon-types are defined by the Table of Random Weapon-Types

A random weapon has a weapon-type. The weapon-type of a random weapon is usually dagger. Understand the weapon-type property as describing a random weapon.

Table of Random Weapon-Types
weapon-type
crude maul
dagger
shortsword
broadsword
shortstaff
crimson staff

Weapon-title is a kind of value. The weapon-titles are defined by the Table of Random Weapon-Titles

A random weapon has a weapon-title. The weapon-title of a random weapon is usually tiny. Understand the weapon-title property as describing a random weapon.

Table of Random Weapon-Titles
weapon-title special
tiny false
Icegnasher true
Flamebiter true
Silverwind true
Korrnak true

Weapon-end is a kind of value. The weapon-ends are defined by the Table of Random Weapon-Ends.

A random weapon has a weapon-end. The weapon-end of a random weapon is usually punyness. Understand the weapon-end property as describing a random weapon.

Table of Random Weapon-Ends
weapon-end
punyness
the steed
flame
frost
awesomeness

Rule for printing the name of a weapon:
let wt be the weapon-title;
if the special of wt is true, say "[wt]'s ";
otherwise say "[wt] ";
say “[weapon-type] of [weapon-end]”.

Rule for printing the plural name of a weapon:
let wt be the weapon-title;
if the special of wt is true, say "[wt]'s ";
otherwise say "[wt] ";
say “[weapon-type]s of [weapon-end]”.

When play begins:
repeat with item running through all random weapons:
now the weapon-type of item is a random weapon-type;
now the weapon-title of item is a random weapon-title;
now the weapon-end of item is a random weapon-end.

The Lab is a room. In the lab are ten random weapons.

test me with “get Flamebiter’s / get dagger / get all Korrnak’s / get all broadswords”.[/code]
If I were you, though, I’d make the weapon types different sub-kinds of weapons. You’re probably going to have different properties for each type (damage, etc.) and keeping track of all that using type as a kind of value is just going to make you crazy. I’m guessing you didn’t do this in the first place since you didn’t want to define a bunch of extra objects from the get-go.

If this is the case, you should check out Jesse McGrew’s “Dynamic Objects” extension. It allows you to dynamically create “clones” of different objects at runtime (the properties of which you can then change). I’ve tried it and it works great, but only for Glulx games.

HTH!

Hmm,

While playing around with the above code, I’ve noticed a weird bug. The parser recognizes “get Flamebiter’s” or “get all Icegnasher’s” or “get both Silverwind’s”, but doesn’t accept “Korrnak’s” at all. Curiously, if I change the name to “Korrnack” (with a “c”) in the code, the parser acts fine. How could this be…?

edit: Duh… nevermind. Korrnack with a “c” has more than seven letters. Inform ignores the rest in this case. That’s the only reason it accepted the apostrophe “s” in the first place. 4am, I guess it’s time for bed.

Wow, thank you! This helps so much! But yes, about the factors like damage, I was thinking of my main option being setting the damage of a weak weapon between blah blah blah and blah, and same for the medium weapons, only stronger, and so on. But thanks for the idea!
EDIT: Okay I get this problem:
In ‘The weapon-type of a random weapon is usually dagger’ you give a value of the weapon-type property as ‘“dagger”’, but this ought to be a weapon-type, not some text.
DOUBLE-EDIT: I fixed that, now the problem is with the last paragraph, what with ‘repeat through’… you’re working on a not-latest version of IF, aren’t you? Cause’ I’ve tried a lot of things with that paragraph now.
TRIPLE-EDIT gasp: I fixed that too, in the only way I knew of, I guess. But now it doesn’t call random weapons by their name. Geh!

No, I’m using the latest version (5t18). The problem with the new “pythonesque” indentation style is that the tabs tend to get screwed up between cuts - and - pastes from newsgroups, message boards, email, etc. When I cut - n - pasted my above code, I got an error too, which I could fix like this: (replace “{tab}” with an actual tab stop)When play begins: {tab}repeat with item running through all random weapons: {tab}{tab}now the weapon-type of item is a random weapon-type; {tab}{tab}now the weapon-title of item is a random weapon-title; {tab}{tab}now the weapon-end of item is a random weapon-end.If this doesn’t work, you can still go back to the old syntax:(in which line indentation is ignored)When play begins: repeat with item running through all random weapons begin; now the weapon-type of item is a random weapon-type; now the weapon-title of item is a random weapon-title; now the weapon-end of item is a random weapon-end; end repeat. Either way, it works for me. Here’s a sample of the output:

Note that step #3 doesn’t work correctly because the name is seven letters long (see my second post, above). If I get time later, I’ll see what I can do to make that part work better.

Wow! I finally got it working. Completely. Thank you soo much! :smiley: