Trading

I wrote this:

[code]The onlyroom is a room.
Mayuta is a person in the onlyroom.
Mayuta is carrying a scythe.
Understand “knife” as scythe.
There is a radio here. There is a doodad here.

Trading is an action applying to one carried thing and one thing.
Understand “trade [thing] for [thing]” as trading.

Check trading (this is the whatever rule):
Unless the first noun is the radio and the second noun is the scythe,
say “Your trade offer was rejected” instead.[/code]

Which seems to me to be fairly parallel to the catching-the-cat action in the Inform Questions thread, but it doesn’t work. Inform doesn’t understand the unless condition.

Since it makes no sense to trade when no one is in the room, I’d also like to do something like

[code]Check trading:
If the player can not see a person
say “There’s no one here to trade with.” instead.

Check trading:
If the player can not see Mayuta
say “Your trade offer was rejected.” instead.[/code]

This doesn’t work either – inform says it doesn’t understand the if statement.

I also tried “cannot” instead of “can not” and “Unless the player can see Mayuta” to no avail.

Incidentally, can I have more than one “check” statement?

When I can get past this first set of errors, I’ll add something like this:

Carry out trading: say "You motion to Mayuta that you[apostrophe]d like to trade your radio for his knife. He smiles, nods in agreement, and you exchange the goods."; move radio to Mayuta; move scythe to the player.

Edited to add: just realized that I also have to check that Mayuta is carrying the scythe. Haven’t thought that one out yet.

Though I am fairly new at this, I will give this smoe thought and see if I can jury rig you an answer.

Especially as you mentioned a problem solved in my thread.

Give me a bit and I shall get back to you. :slight_smile: If succesful.

First thing:

This is not correct syntax; it creates two items, one called “radio here” and another called “doodad here” and places them off stage. Try: A radio and a doodad are in onlyroom. Next, there is no variable called “first noun.” It’s just “noun” and “second noun.” Your other two check rules are just missing commas (or the word “then”). As in:[code]Check trading:
If the player can not see a person,
say “There’s no one here to trade with.” instead.

Check trading:
If the player can not see Mayuta then say “Your trade offer was rejected.” instead.[/code]Other than those little things, you seem to be doing fine :slight_smile:

One tip: I’ve noticed that for me, when Inform doesn’t understand a phrase I think it should (like an “if… then”), it almost always turns out to be a mistake in punctuation in the phrase itself, or the line immediately preceding it. The next most common mistake for me is a misspelling of a variable name or action name. My personal fave is “Instead of examing” for “Instead of examining.” :smiley:

Skinny Mike is all about the helpfulness.

DOH! What a bunch of stupid mistakes. Maybe I was tired when I tried to program that one.

Thanks Skinny Mike.

Argh! I keep running into a set of bugs that is related.

The first thing doesn’t make sense of course, since you don’t end up with it after “first taking” it. The second one caused nothing to fire because

Instead of trading when the player is not carrying the noun: say "You aren't carrying it."

didn’t override it, and my trade code handling what to do when you aren’t carrying the item didn’t fire, nor did the code when you are carrying it. So you’re left with a blank line.

Can I disable whatever rule that makes you “first take” an item that you’re not holding, before trading it, eating it, wearing it, etc? It has given me trouble with all three of those and now with trade!

Edited to add: Oops, the code for when the player is carrying the item did in fact fire, after I fixed something about it that was broken. I still don’t like this “first taking” business though.

Easy enough for the trading action; just take out the “carried” requirement of the rule definition. As in: Trading is an action applying to two things. This removes the implicit take, so if you want to make sure the player has the thing to be traded, you’ll have to have a separate rule to check that (which it looks like you already do). Note that you can also override implicit takes in actions defined by the standard rules as applying to carried things (i.e. the built - in actions like eating and wearing). This is a little more complicated – see ex 354 “Lollipop Guild” – but in the case of trading, that would be over - kill. More advanced still would be the use of Eric Eve’s “Implicit Actions” extension (avail. on I7 website) which – among other awesome things – rewrites the way implicit actions are reported so that they make more sense (i.e. “(first trying to take the scythe)”).

Cool. Thanks Mike.

Code:

[code]Mayuta is a person in the onlyroom.

[code about other people and items and scenery, omitted]

Instead of trading when the player is not carrying the noun:
say “You aren’t carrying a [noun].”.

Instead of trading when the second noun is not portable:
say “You can’t take the [second noun].”.

[other stuff regarding trading with people, omitted]

Instead of trading when the second noun is in the location: [this is for “trading” when no one is around]
say “You drop the [noun] and pick up the [second noun].”;
move noun to the location;
move second noun to the player.[/code]

Game play:

What the heck? I thought the earlier “insteads” overrode the later ones, and in fact that usually seems to be the case. I thought that kind of made up for the lack of nested ifs. Not true?

Do I really need to repeat all my earlier conditions in the statement “Instead of trading when the second noun is in the location” ?

Edited to add: If I specify that Mayuta is not portable, then things work as I would like. But people are already not portable! “Take Mayuta” -> “I don’t suppose Mayuta would care for that”

Nope, it’s actually that more specific "instead"s override less specific ones. If you have an “instead of examining something” rule and an “instead of examining the doggy” rule, if the player examines the doggy the one about examining the doggy will be used, no matter the order those two rules appear in. You can also just create one general rule that has some “if” statements in its body that check various conditions manually.

Hope this helps. I’d write up some example code, but it’s bed time!

This is true, however there are rules with regard to specificity which are first mentioned in ch. 18.5 and broken down in detail in 18.18. This specificity only comes into play when you use a conditions (such as, but not limited to, “when”) in the preamble of a rule (the part before the first colon). You can avoid this by just using rules like:Instead of trading: if foo then bar. Instead of trading: if foo2 then bar 2.These rules will be checked in source order.

What lack of nested ifs? Nesting of if… then statements is allowed – except inside of quoted text. Do I misunderstand you?

People are portable (after all, they aren’t fixed in place, which is the opposite property). They are not takeable due to the “can’t take other people rule” which would be checked if you used the phrase “try the player taking the noun.” Instead you’ve merely moved the object to the player. You as the author can do that.

Thanks Radix! That helps, no code needed. That, and the fact that I just learned in another thread that I can use multiple otherwises.

People are portable but not takeable, I see.

Any time I had tried to do nested ifs, I got a ton of errors. Perhaps I don’t know the syntax rules – I’ll see if I can find something in the documentation. It would definitely help if I could use them.

Thanks Mike!

Looking again upthread, I guess we kind of got on a tangent about rule order that isn’t really the issue with regard to this rule:

The thing is, you need to be careful when moving objects around. Inform assumes that you, the omnipotent author, know what you’re doing and if you say “move something to somewhere” it usually will (in some cases even if it causes the game to crash!) This is where the use of the “try” and “try silently” syntax (ch. 7.4) comes in handy. Returning to the above example, it looks like you want to have a “trading with no one” action here – dropping one object and taking another, with a single message to describe the combined actions. Here’s one way of doing it which uses a nested if (I used the begin… end if syntax so you wouldn’t have to worry about the tabs getting messed up in cutting / pasting):Instead of trading when the second noun is in the location (this is the trading when no one is around rule): silently try dropping the noun; if the noun is in the holder of the player begin; silently try taking the second noun; if the player carries the second noun begin; say "You drop the [noun] and pick up the [second noun]."; end if; end if.Note that when you use begin, you follow it with a semi - colon, not a colon. The upshot is you don’t have to worry about the indenting. In the above code, we use “silently” to supress the normal reporting of taking and dropping. First, the player tries to drop the noun and if the drop is successful (there are some situations where it might not be) tries to take the second noun. Next, if the take was successful, the desired message is printed. If either of these tried actions fail – if you try to take a person, for instance – the normal refusal message (“I don’t suppose Mayuta would care for that”) will print. The other upshot of using “try” is that you don’t have to worry about duplicating all twelve of the different checks the standard rules perform for taking something. Hope I explained that okay. :slight_smile:

That’s strange - nested ifs should work fine. Are you using colon-and-indent syntax? Here’s an example:

instead of tasting the sun:
	If the player carries wax and the player carries feathers:
		say "(first making wings from the wax and feathers)"
		if the strength of the player > 50:
			say "With your great strength you leap upwards and flap your wings. When you get to the sun, you give it a lick; it tastes like hot chocolate."
		otherwise:
			say "You jump and flap, but alas, your puny strength is not enough."
	otherwise:
		say "Yeah right."

Make sure you get the colons and tabs right.

Thanks to both of you. Mike, it’s good to know about that “try” syntax. It will probably help me in some other areas too.

Radix, I don’t remember what punctuation I was using now – I think that what happened was that I tried it unsuccessfully several times, probably with the wrong punctuation, then looked for it in the manual and didn’t find it, then saw a bunch of examples that seemed to be working around it, and finally assumed it couldn’t be done. Thanks for the example, I’m sure I’ll be able to make it work now by following your syntax and punctuation.

I’ve decided to allow trading with any NPC (why not!?), even though only a few trades are profitable. I have programmed trading as such, with repeating code for each person:

[code]Instead of trading when the player is carrying the noun and the player can see Mom and Mom is carrying the second noun:
say “You offer to trade your Mom the [noun] for the [second noun]. She accepts your offer and you exchange the goods.”;
move noun to Mom;
move second noun to the player.

Instead of trading when the player is carrying the noun and the player can see Granny and Granny is carrying the second noun:
say “You offer to trade Granny the [noun] for the [second noun]. She accepts your offer and you exhange the goods.”;
move noun to Granny;
move second noun to the player.[/code]

I knew it was inelegant from the start, but I couldn’t seem to make something like this work:

Instead of trading when the player is carrying the noun and the player can see a person and the person is carrying the second noun: say "You offer to trade the [noun] for the [second noun]. Your offer is accepted."; move noun to the person; move second noun to the player.

Is there any way I can do this “the person” thing? I’m now regretting the-block-of-code-for-each-person because I’d like to cause certain trades to have certain results, without writing the whole thing over and over again.

Well, again, “the person” or “a person” both mean “any person anywhere in the game”, not “the same person previously referred”. Try this:

[code]Definition: a person is another if it is not the player.

Instead of trading when the player is carrying the noun and the player can see another person (called the trading partner) and the trading partner is carrying the second noun:
say “You offer to trade the [noun] for the [second noun]. Your offer is accepted.”;
move noun to the trading partner;
move second noun to the player.[/code]
This of course works elegantly only if there’s only one person in the location.

Note that even the player is a person and we can always see ourselves. That’s why you need to specify that we mean someone who is not the player.

Nitku, thanks so much.

Actually I think it will work when there is more than one person in the location, because the first test for trading is that the thing you want to trade for is in the location. There is only one of each thing, so once someone is holding that thing, they are the trading partner. Between the rules I’ve already created and the help you’ve given me, I think I can deal with more than one NPC in the location.

Thanks again!

Ah, you are absolutely right. My mistake!