PLEASE HALP!!!! lol (random item from inventory!)

hi everyone! its great to find a forum of other IF folks!

so check it ert, im writing my first IF and im very excited about it, its grooving pretty nicely but im totally stuck and cant find an answer in the documentation.

im using Inform 7.

so, in my story, i pretty much make fun of the idea of the player thinking he is a warrior, when hes not, so when the player tries to go all Conan, i pretty much make it kinda realistic, humorous, or difficult.

ok, so if u try to “throw knife at guard” (for instance), i have different random things occur instead. one thing im struggling to figure out is having the player take a random, non-weapon, item from inventory instead but for the life of me, i cannot figure out the code to make that work!!!

HALP!!!

and please dont make fun of me or anything, im hoping this is a friendly community, im going thru a lot of crap in my life and im really hoping to avoid elitist IF people or whatever, this is my first post, i hope u guys make me feel welcome here. ok thanks!

It would be helpful if you could post some code to show how far you’ve gotten with this idea.

I’m guessing you could do something like this (not tested):

A weapon is a kind of thing. The knife is a weapon.

Before throwing a weapon at something when the player carries something that is not a weapon:
    Now the noun is a random thing carried by the player that is not a weapon;
    Say "Before you realize what you've done, you grab [the noun] instead of your weapon and aim it at [the second noun]."

Interestingly, that rule doesn’t actually prevent the player from choosing the knife.
I’m not sure why, but perhaps Inform interprets the description “a random thing carried by the player that is not a weapon” as “a random thing carried by a player who is not a weapon”!

Anyway, “a random thing that is carried that is not a weapon” works.

(Also, if you let your would-be Conan actually throw things, make sure all “throw-aways” are actually dropped and don’t remain carried.)

Instead of throwing a weapon at something when the player carries something that is not a weapon: let the mishap be a random thing that is carried that is not a weapon; say "Before you realize what you've done, you grab [the mishap] instead of your [noun] and hurl it at [the second noun]."; try silently dropping the mishap.

Pretty sure that’s what happens. This seems to trip people up a lot.

I suppose you could also do this with a property of things (not tested):

A thing can be weapon or nonweapon. A thing is usually nonweapon. Before throwing a weapon thing at something: if the player carries something that is nonweapon: let the mishap be a random nonweapon thing that is carried by the player: "Before you realize what you've done, you grab [the mishap] instead of your [noun] and hurl it at [the second noun]."; move the mishap to the location; otherwise: say "You somehow manage to throw [the noun] straight up in the air, but manage to dodge out of the way before it hits you in the skull."; move the noun to the location; stop the action.

hey, thanks everyone! these are great! i did figure out a code that works [a random thing carried by the player that is not the noun], and i did specify things are weapons or not-weapons, and this way if they throw something, it just drops it, if they throw something at the guard and its not a weapon, it does the “lack the nerve” comment, and if they try to throw the weapon, then it does the random stuff including the humorous grabbing of something else.

but thanks for the advice, all of it gives me some insight into the coding that im sure i will use elsewhere eventually! and thanks for being friendly about it!