Okay. I am trying to create an item in Inform which has a rule of Smoking Cigars. I want the cigar to be ‘new’ when the player first smokes one, and then increment it’s value to the next ‘category’ (smoldering), etc, and so forth until the cigar is spent, then it’ll be discarded. (That’s the plan for this specific type of object in this IF game).
This is all the code I was able to write so far but inform is having a fit trying to parse my code to increment the ‘next value’ Right now I don’t have the entire code in mind written out yet.
Smoking is an action applying to one thing. A cigar is a kind of thing. Understand "smoke" and "smoke [cigar]" as smoking. Understand "stogie" as a cigar. Understand "cigars" as the plural of cigar.
Durability is a kind of value. The durabilities are new, smoldering, half-used, and stubby. A cigar is a kind of thing. A cigar has a durability. The durability of a cigar is usually new. A stogie is a cigar.
Report smoking:
if player has cigar:
say "You light up your [durability of the stogie] cigar and start smoking contemplatively.";
else:
say "You pat your pocket and find no cigar. Alas!"
anytime I put an increment or increase durability of the stogie by 1, it throws a fit. So I’m not sure if I’m missing anything obvious or am doing something wrong. I know I will have to do an if condition to prevent an (illegal out of bounds) sort of thing once it passes “stubby”, but I would like to at least get the code working.
It looks like you’re sort of following 18.24. Writing a paragraph about in the “Reflections” example where it talks about “brightness” as a kind of value for a torch that burns down.
Exactly. Trying to. But the problem is I want to increment (or decrement) (or even increase/decrease… not sure which of the two sets deal with text more). For at least all those values then once done, have the player ‘automatically’ discard it. (I’ll try to read that example in the meantime)
I believe you have to add a check to make sure you’re not already at the end of the list or it will loop back to the beginning. So
Carry out smoking a cigar:
unless the cigar is stubby:
now the durability of the cigar is the durability after the durability of the cigar.
You’ll have to decide how or when to discard the stubby one.
My WIP uses value updates like this often and I find things like this useful for my check/carry out/report statements.
Definition: A cigar is smokable if its durability is less than stubby.
That would give you option of leaving stubby cigars visible but unusable rather than just having them vanish entirely. You could also then use phrases like “if the cigar is smokable” or “if a smokable cigar is carried” or “a random smokable cigar”
You’re right, I just tested and you have to say “the noun”
Carry out smoking a cigar:
unless the noun is stubby:
now the durability of the noun is the durability after the durability of the noun.
I also realized that as-written this messes up the report rule because it degrades the durability before saying “You light up your [durability of the stogie]” so there’s an off-by-one error that will have to be worked around. I’m not sure the best way to handle that.
I’ll also mention that if you think you’ll be changing the value in several different places you can use a to phrase. Like, if say an dropped one will slowly burn down or if during a specific scene you want to force the player to smoke.
To degrade (DT - a thing):
unless the durability of DT is stubby:
now the durability of DT is the durability after the durability of DT.
That would let you say “degrade stogie” in the code without having to reenter the whole unless/now statement and skip the report smoking statement. In my WIP this is really useful, but for other projects it’s more work and the carry out is plenty so YMMV.
edit: corrected first code block as pointed out below
You need to say “the noun” in both places (that is, it should be “unless the noun is stubby”) or Inform will pick one of the game’s cigars more or less at random and check its stubbiness, rather than the particular one the player is trying to smoke.
Yeah, I’ve been burned by this before. Inform appears to interpret “the cigar” the same as “a cigar” in code, even when it’s clear that these are two different things.
Maybe action variables? Something like this:
The smoking action has a durability called the current durability.
Setting action variables for smoking:
now the current durability is the durability of the noun.
Then the report rules has to be changed to this:
Report smoking:
if player has cigar:
say "You light up your [current durability] cigar and start smoking contemplatively.";
else:
say "You pat your pocket and find no cigar. Alas!"
Also, I also just realised something. The original code has this line:
If you type “smoke” in the compiled game, you’ll get an unhelpful “You must supply a noun.” You could implement a “smokable” adjective, as @CortJstr suggested, and then write:
Rule for supplying a missing noun while smoking:
now the noun is a random smokable cigar carried by the player.
Smoking is an action applying to one touchable thing. Understand "smoke" and "smoke [cigar]" as smoking. A cigar is a kind of thing.
Rule for supplying a missing noun while smoking:
now the noun is a random smokable cigar carried by the player.
Current durability is a kind of value. A cigar has a current durability. The current durabilities are new, smoldering, half-used, stubby, and spent. The current durability of the cigar is usually new.
Definition: A cigar is smokable if its current durability is less than stubby.
Carry out smoking a cigar:
unless the noun is spent:
now the current durability of the noun is the current durability after the current durability of the noun.
Report smoking:
if player has cigar:
say "[if new]You light up your cigar and start smoking contemplatively[else if smoldering]You puff on your cigar and relax in it's smoky ambience[else if half-used]The cigar is soothing your nerves[else if stubby]You think about putting the cigar out soon[else if spent]You put the embers out and tuck it somewhere away[end if].";
else:
say "You unfortunately aren't carrying any cigars at the moment." [/code]
(not sure how to format it in code block again?) This is what I’ve managed to cobble together based on your suggestions and all. It does work except for the cigar being able to be smoked while “spent” and in the inventory. I kinda wanted the cigar itself to make it obvious it’s not useable anymore. I probably missed something here lol.
Is there a reason you don’t use check rules instead of report rules to, er, check if the player has a cigar?
A “check smoking” rule that prevents smoking of spent cigars, maybe? Anyway, here is what I managed to put together that kind of does some of what you want. I’m not sure whether you wanted the cigar to disappear when “spent” or just discarded, so I just left spent cigars in the player’s inventory.
The Smoking Room is a room.
Smoking is an action applying to one touchable thing. Understand "smoke" and "smoke [cigar]" as smoking. A cigar is a kind of thing.
Rule for supplying a missing noun while smoking:
if the player carries a smokable cigar:
now the noun is a random smokable cigar carried by the player;
else:
say "You aren't carrying any smokable cigars at the moment."
Current durability is a kind of value. A cigar has a current durability. The current durabilities are unused, new, smoldering, half-used, stubby, and spent. The current durability of the cigar is usually unused.
Definition: A cigar is smokable if its current durability is less than spent.
The smoking action has a current durability called the durability in question.
Setting action variables for smoking:
now the durability in question is the current durability of the noun.
Carry out smoking a cigar:
unless the noun is spent:
now the current durability of the noun is the current durability after the current durability of the noun.
Report smoking:
say "[if durability in question is unused]You light up your cigar and start smoking contemplatively[else if durability in question is new]You puff on your cigar and relax in its smoky ambience[else if durability in question is smoldering]The cigar is soothing your nerves[else if durability in question is half-used]You think about putting the cigar out soon[else if durability in question is stubby]You put the embers out and tuck it somewhere away[end if].";
The player carries a cigar.
Check smoking:
unless the player has a cigar:
say "You unfortunately aren't carrying any cigars at the moment." instead.
Check smoking:
if the noun is spent:
say "[The noun] is spent." instead.
Before printing the name of a cigar: say "[current durability] ". Understand the current durability property as describing a cigar.
My original idea was to have the Player be able to ‘smoke’ a cigar, and have it gradually burn down everytime they did the smoke verb. Then I was trying to figure out how to just ‘discard it’ (get rid of it from inventory, or erase it, or something) or ‘somehow’ make it so it was obvious it wasn’t useable anymore. (like printed name, etc). I just couldn’t figure out how to write it exactly. And it would apply to all cigars that the Player manages to pick up (and carry) in the game.
And thank you all for all your help so far. I’m not entirely new to Inform, but mainly to the “Check/Report type of things” along with Scenes, heh.
so far I’m u sing the code you provided, and it’s working awesome so far. At first I was wondering why the player kept having two cigars. (I had “The Player carries a cigar” again in the source code lol, in addition to yours in the code you provided). I need to add a check or a rule so they can only carry one cigar at one time, since I kept running into the problem. “Which cigar do you mean?, etc” if I had two cigars in the inventory. So I’ll try to figure that one out.
If you have a specific instance where the player gains a cigar, you could add some check code checking whether the player already has a cigar, then preventing them from taking another one.
Instead of taking a cigar:
if player carries an unused cigar:
say "[if unused]You already have one in your pocket, and don't need one.[else if spent]You don't see a reason to take it.[end if]";
else:
if player carries a spent cigar:
say "'Hmm, I wonder if I should? I could use one.'";
now the player carries a random smokable cigar;
Now I’m trying to figure out how to restrict where I can drop the spent cigar itself. Doing some reserach on that… (like an ashtray, or garbage bins, etc) sicne I accidentally put one in a humidor with other unused cigars, and can’t get it out, and it looks ‘wierd’ to have it there logically.
the laboratory is a room.
a thing can be a cigar disposal.
an ashtray is a container in laboratory. it is a cigar disposal.
a mug is a container in laboratory.
a table is a supporter in laboratory.
a cigar is a kind of thing. a brown cigar is a cigar. the player carries the brown cigar.
to cigar disposal redirect:
say "You should dispose of that in an ashtray.";
instead of dropping a cigar:
cigar disposal redirect;
instead of putting a cigar on something:
cigar disposal redirect.
check inserting it into:
if the noun is a cigar:
if the second noun is a cigar disposal:
say "You throw away the cigar.";
rule succeeds;
else:
cigar disposal redirect instead.
test me with "drop cigar / put cigar on table / put cigar in mug / put cigar in ashtray".