Weight System acting really weird

Im sitting here trying to write and incorporate a carrying capacity system relying on weight instead of capacity. However i’m getting some weird numbers, when i try to work with the total of a numeric property.

This is how i define weight:

A weight is a kind of value. 
1.0 kg specifies a weight.
Everything has a weight.
A thing usually has a weight 0 kg.
A person usually has a weight 80 kg.

The carrying capacity of the player is 999.
A person has a weight called Carry Limit. The Carry Limit of a person usually is 20 kg.

My first attempt for saying the total weight of items carried by the player looked like this:

To say Carry Weight of the player:
	let cw be the total weight of things carried by the player;
	say "[cw]".

This gave me weird numbers when carrying more than 1 item:

------------------
Carry/Weight
------------------
Limit: 20.0 kg
Weight: 1.70141 × 10^38 kg
------------------
Inventory
------------------
two Demonic Daggers

Both daggers have a weight of 1 kg. Which is why it don’t makes sense.

So i tried doing something inspired by the examples provided in Inform doc:

To decide what weight is the Carry Weight of the player:
	let sum be the total weight of things carried by the player;
	decide on sum.

This gave me the same results from before.

The overall overburdened system looks like this, though i don’t think it’s super relevant:

Every turn:
	if the total weight of things carried by the player is greater than the Carry Limit of the player:
		if the player is not-overburdened:
			now the player is overburdened;
	otherwise:
	[else if the total weight of things carried by the player is less than the Carry Limit of the player:]
		if the player is overburdened:
			now the player is not-overburdened.

A scene can be sc-overburdened or sc-underburdened.
Instead of going somewhere during a sc-overburdened scene:
	say "You are currently carrying too much and overburdened, drop something!".
	
Every turn during the Overburdened-by-weight, say "You are still overburdened by weight!".

When Overburdened-by-weight begins:
	say "You are currently carrying too much and overburdened, drop something!".

When Overburdened-by-weight ends:
	say "You are no longer overburdened by weight!".

Overburdened-by-weight is a sc-overburdened recurring scene.
Overburdened-by-weight begins when the player is overburdened.
Overburdened-by-weight ends when the player is not-overburdened.

Anyone got any ideas why total doesn’t work with weight values?

That seems like a bug. I’ve reported it.

Unless someone has another workaround, maybe you should just specify weights in grams so you don’t have to use decimal points? (I checked the Metric Units Extension by Graham Nelson and it doesn’t work either.) You can do it like this:

1 g specifies a weight. 1 kg specifies a weight scaled up by 1000.

And then you can say that the demonic daggers have weight 1 kg, and if the player has two of them and something else that weighs 100 g then the total weight will still display as “2.1 kg.”

Well that seemed to make it work just fine. Weird though.

Thanks!

It looks like the “total weight” phrase is using integer addition instead of floating-point addition, so when you give it floating-point numbers you get a garbage result. Unfortunately this phrase is programmed in the compiler, so there’s no good way to change it except waiting for the next release.

If you want to use real-number arithmetic I guess you can roll your own phrase to add up total weights:

To decide what weight is the sum total weight of (OD - description of things): let totallist be the list of OD; let tempweight be 0.0 kg; repeat with item running through totallist: increase tempweight by weight of item; decide on tempweight.