Adding item weight to your project

The following is a fully functional example that will show you how to implement a weight system in your game. The example uses the metric system but can be converted to the imperial system.

Everything can have a weight value including persons. So, for instance, the player would not be able to carry any persons whose weight is greater than 80 kg.

All objects can have weight that will affect the carry weight of the player. If the player’s inventory is too heavy, the player will no longer be able to move until the player drops some items from inventory.

If you want the player not to exceed their carry weight limit when picking up an object, you can use the following snippet which limits the weight picked up:

Before taking something (called the item):
	let cw1 be the total weight of things carried by the player;
	let cw2 be the weight of the item;
	if (cw1 plus cw2) is greater than the carry limit of the player:
		say "You will exceed your carry limit so you leave [the item] alone.";
		stop the action.

I hope this helps people who wish to implement a weight system in their projects.

Enjoy.

A person can be overburdened or unburdened. A person is usually unburdened.

The carrying capacity of a person is 10.

A weight is a kind of value.
1 g specifies a weight.
1 kg specifies a weight scaled up by 1000.

Everything has a weight.
A thing usually has a weight 0 kg.

A person has a weight called Carry Limit.
The Carry Limit of a person is usually 45 kg.

ShowItemWeight is an action applying to nothing.
Understand "show stuff" or "my stuff" as ShowItemWeight.

Garden is a room. "Fresh air, wind whipping through your hair, the smell of flowers lingers in your nostrils as you stand looking at all this natural beauty. A path south leads to a forest."

Forest is a room. "You are in the middle of a small forest. There are many trees surrounded by varying sizes of green and yellow bushes. A path north leads to a garden."

Forest is south of Garden.

A barbell is a kind of thing. The weight of a barbell is 10 kg.
There are ten barbells in the Garden.
The description of a barbell is "A barbell is used for weight training. Each barbell weighs 10 kg."

A gold ingot is a kind of thing. The weight of a gold ingot is 12 kg.
There are eleven gold ingots in the Garden.
The description of a gold ingot is "Gold from the Incas is priceless. Each gold ingot weighs 12 kg."

A scooter is a thing. The weight of a scooter is 140 kg.
There is a scooter in the Garden.
The description of a scooter is "This scooter is small and easy to use. Each scooter weighs 140 kg."

Instead of taking inventory (this is the new inventory listing rule):
	if the number of things enclosed by the player is 0:
		say "You don[apostrophe]t seem to have anything at the moment.[line break]";
		say "Your carry weight limit is [Carry Limit of the player].[line break]";
	else:
		say "You are carrying [a list of things carried by the player].[line break]";
		say "Your current carry weight is [no line break]";
		Decide Carry Weight;
		say "Your carry weight limit is [Carry Limit of the player].[line break]".

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 unburdened:
			now the player is overburdened;
	otherwise:
		if the player is overburdened:
			now the player is unburdened.

Instead of going somewhere when the player is overburdened:
	say "[bold type]You are currently overburdened and cannot move.[roman type][line break]";
	say "Your current carry weight is [no line break]";
	Decide Carry Weight;
	say "Your carry weight limit is [Carry Limit of the player].[line break]";
	repeat with item running through things carried by the player:
		say "The [item] weighs [weight of item].[line break]";
	stop the action.

Carry out ShowItemWeight:
	say "Your current carry weight is [no line break]";
	Decide Carry Weight;
	say "Your carry weight limit is [Carry Limit of the player].[line break]";
	say "[line break]";
	repeat with item running through things carried by the player:
		say "The [item] weighs [weight of item]. [line break]";
	say "[line break]";
	say "Your carrying capacity is [carrying capacity of the player] items.[line break]";
	stop the action.

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

This looks like a good addition to the many ways there are of simulating carrying capacity. Check the Recipe Book for more:

http://inform7.com/learn/man/RB_10_5.html