# Assigned values....

In my review game, I assign weights to things, with this assertion–

``Everything has a weight.  A thing usually weighs 1oz.  ``

(to account for any trivial items)

If I want to get a total weight of things carried(by simply using ‘total weight of things enclosed by the player’ for example), I find that if anything carried happens to have a ‘part’, the weight of the part is included, because it matches with ‘thing’ and was thus assigned a weight of its own.

What this boils down to is that I am trying to figure out a blanket assertion to make to declare ‘parts’ as not having weights of their own(as I include that info in the weight of the objects that they are parts of). I tried ‘Everything except things that are part of a thing has a weight’(no effect), and ‘A part of a thing weighs 0lb’(no effect)(neither returned a problem message, though). What did work was giving each specific part 0lb–but I really don’t want to have to do this. Is there any way that I can assert something that would be true of all ‘parts’ across the board??

Thanks

```When play begins: repeat with item running through things: if item is part of something: now the weight of item is 0oz.```

Also, not sure if it matters, but you seem to be switching between oz and lb.

HTP,

I had defined the ounce as 1/16th of a pound like so–

``1oz specifies a weight scaled down by 16.``

That allowed me to give weights in ounces to objects. Of course if a rule calls for reporting back, it gives the weight in pounds, so an ounce would be reported as 0.06lb. I could probably do a little mathematical fiddling to get it to report back in pounds and ounces, but this is just a review game.

Thanks to you both.

HanonO,

You gave me the word I needed–this worked–

``A thing which is a part of something weighs 0lb.``

(‘A thing which is a part of a thing weighs 0lb.’ did not work)

Thanks

[code]A thing usually weighs 1lb.

A thing which is a part of something weighs 0lb.[/code]

When I test this, everything in the game winds up at 0lb.

I think you need the when-play-begins solution.

Zarf,

That’s odd.

Because now this works perfectly–

[code]A weight is a kind of value.

10lb specifies a weight. 1oz specifies a weight scaled down by 16.

Everything has a weight. The weight of the player is 217lb. The weight of John Diddling is 175lb.

A thing usually weighs 1oz. A thing that is a part of something weighs 0lb. The nickel-plated revolver weighs 2lb. The radio weighs 1lb. A popcan weighs 1lb. The trench coat weighs 10lb. The fedora weighs 1lb. The duffel bag weighs 2lb. A cutknife weighs 2oz. The large wedge of cheese weighs 5lb.

Definition: A thing is light if its weight is 5lb or less.
Definition: A thing is heavy if its weight is 22lb or more.

A long bench is here. It is scenery and an enterable supporter. The description is “It’s just a long wooden bench, with a sensitive digital scale fixed to the end of it.”

A digital scale is here. It is scenery. The description is “It’s attached to the bench by unseen wires. The readout says, in red digits–[total weight of things enclosed by the long bench].”[/code]

Of course when you put anything on the bench, the scale will register the weight of the thing and anything inside or on it. If the player sits on it, it will give the total weight of the player and anything carried/enclosed. It works fine. I wonder if it made a difference that i said ‘A thing usually weighs 1oz.’…??

I think it’s only working because you’ve specified all the weights; anything you don’t specify a weight for will get set to 0lb instead of 1oz. I don’t know why your code has that effect though.

(Actually I’m surprised that the line “A thing that is a part of something weighs 0lb.” has any effect at all, or even compiles; I’d imagine that being a part of something can only be tested at runtime, not during compilation.)

Actually, there are a number of things in the game that I didn’t specify a weight for–a number of coins, nails, piece of paper–they each came out as 1oz (as I didn’t specify them, I figure they followed the ‘usually’ assertion)–the things listed in the paragraphs above are the only ones specified. After I put in the ‘part of’ assertion, and tried putting things on the bench, nails, coins, myself, myself loaded up, they all summed up correctly. Everything in my code above follows what I have thus far gone over in the manual. I was able to give weights to whole kinds–popcan(there are three), cutknifes(3 of these)(and of course, ‘thing’ is a kind itself).
I wonder if it also makes a difference that when a weight is reported back, if you use pounds(here, lb) and ounces(oz), it is reported back in the original unit (pounds), and if it’s less than 0.1lb, it’s reported as 0lb? I notice that my 1oz items, if set alone on the bench, are reported back as 0lb(because an ounce is approx 0.06lb), but when a number of them are set on, they return a correct sum??(2 1oz items would report back as 0.12lb, three as 0.19lb, etc). Perhaps because these go over 0.1, Inform gave it another decimal place?
Anyway, thanks to you guys’ help, it now works correctly.

Okay, I looked again—you are right, JRB, it is giving weights of 0lb, but when I put things on together, or have the player loaded down, it gives a correct weight to the second decimal place, including with the 1oz things.

I think I’m going to redefine my weight assignments–sticking with ounces–and converting to pounds by simple division.

Thanks and sorry for your trouble.

Update–

I went over Chapter 15 in the manual again, and made some adjustments–I should have started with ounces (the smallest unit), and used–

``` 1 ounce (singular) specifies a weight. 2 ounces (plural) specifies a weight. 1 pound (singular) specifies a weight scaled up by 16. 2 pounds (plural) specifies a weight scaled up by 16. ```.

I removed the ‘A thing that is a part of something weighs 0 ounces’–it seemed to be giving a thing defined as a matching key 0 ounces, and nails and everything not specified 0 pounds(so JRB and Zarf you were right), plus I implemented HanonO’s solution. I also spelled out my units, so they could be reported back ‘written out’. Now my bench reports the correct weight.

Now I am trying to figure out how to get the bench scale to report back weights in whole pounds and ounces, instead of giving a ‘real number’ response (such as 219.31 pounds). I figure it’s going to make use of some form of (if ‘toto’ is our total weight) ‘[INT[toto]]pounds, [(toto-INT[toto])*16] ounces’…??

I tried the following–

```Allweight is a weight that varies. Poundweight is a weight that varies. Ounceweight is a weight that varies. To say totalweight: now allweight is the total weight of everything enclosed by the long bench; if allweight > 1 pound: now poundweight is floor of allweight; now ounceweight is (allweight minus poundweight)*16; say "[poundweight] [if ounceweight > 0 ounces][ounceweight]"; otherwise: now ounceweight is allweight*16; say "[ounceweight]".```

It threw a problem message because the weight variables I created were not of the kind ‘number’, but I tried to treat them as such. Is there a function such as ‘the number part of…’ that I can apply to the total weight, and treat it as a number…?? Here’s the problem message that it threw—

Problem. You wrote ‘now poundweight is floor of allweight’ , but ‘allweight’ has the wrong kind of value: a weight rather than a real number.

I was trying to match this phrase:

floor of (allweight - real number)

I recognised:

allweight = a non-temporary variable, holding a weight

Problem. You wrote ‘now poundweight is floor of allweight’ , but ‘allweight’ has the wrong kind of value: a weight rather than a real number.

I was trying to match this phrase:

floor of (allweight - real number)

Problem. In the sentence ‘now ounceweight is (allweight minus poundweight) *16’ , I was expecting to read a condition, but instead found some text that I couldn’t understand - ‘ounceweight is (allweight minus poundweight) *16’.

Problem. In the sentence ‘now ounceweight is allweight16’ , I was expecting to read a condition, but instead found some text that I couldn’t understand - 'ounceweight is allweight16’.

You can say “the weight of X divided by 1 ounce” to get the (integer) weight in ounces. If you say “1.0 ounce specifies a weight”, then it would be a real number instead.

Thanks Zarf.