How do I count up the volume of all the items in the Inventory? (Solved)

Is there just a term for this? game.pov.volume doesn't seem to work.

I was trying to create a function or turn timer which made a stat game.pov.INV_C (current Inventory weight) equal to the volume of all Child Objects in the player at all times, or each turn at least.

Ultimately I want to keep a Fishing Command from allowing the player to receive a fish if they dont have volume space for it.

I have stats INV_C and INV_M (maximum) on the Character.

I have a status that shows 'Encumbrance 0 / 21' in the panels (INV_C / INV_M)

I need to:
[set variable] game.pov.INV_C = player inventory volume

and for the fishing command I need:
If [fish weight] exceeds [remaining inv space]
then 'Tough luck, buddy!'

examples of what im playing with:

game.pov.INV = game.pov.INV_C + " / " + game.pov.INV_M
game.pov.INV_C = game.pov.volume
  }
  else if (game.pov.INV_C >= game.pov.INV_M) {
    msg ("You couldn't possibly add even one fish to your person...")

Is there just a term for this? game.pov.volume doesn't seem to work.

Generally, attributes such as game.pov.volume hold a static number that has already been calculated. In this case, the volume used for determining whether a player with an empty inventory will fit in a container.

If you're using the built-in volume/weight system, the expression GetVolume (game.pov, false) will calculate the volume of everything the player is currently carrying. (GetVolume (game.pov, true) is the combined volume of game.pov and its contents).

I have a status that shows 'Encumbrance 0 / 21' in the panels (INV_C / INV_M)

Is INV_M the same as maxvolume? Or are you making your own system to replace the built in one?

and for the fishing command I need:

One common way to do this (if you're using the built in inventory volume limits) would be:

MoveObjectHere (some fish)
DoTake (some fish, false)

Or (same thing, slightly more efficient, but slightly less easy to read):

some fish.parent = game.pov.parent
DoTake (some fish, false)

(assuming that some fish is either the fish object, or a variable referring to the fish object)
(if you're cloning the fish at this point, it would be more like

newfish = CloneObjectAndMoveHere (original fish)
DoTake (newfish, false)

)
Instead of putting the fish straight in the inventory, it puts it on the ground next to the player, and then runs the built in "take" command, which already has suitable responses if the inventory is full. Some players prefer this because if they run out of space, they can choose to drop something else to make space for the fish.

If you don't want to do it like that, you'd probably want to do something like:

volume = some fish.volume
foreach (object, GetAllChildObjects (game.pov)) {
  if (HasInt (object, "volume") and GetBoolean (object, "visible")) {
    volume = volume + object.volume
  }
}
if (volume > game.pov.INV_M) {
  msg ("There isn't space for another fish in your pockets.")
}
else {
  some fish.parent = game.pov
  game.pov.INV_C = volume
}

ok, so the GetVolume (game.pov, false) was the syntax I needed to set INV_C to Player carried volume, but I have it in a turn script, so it takes 1 action to catch up and show the correct Status in the panel.

Is there a way to have a script which runs at the end of a turn, or every time the character picks something up?


INV_M is the same as maxvolume, i already used a system for health and food, so i was just doing the same for sake of ease. I could remove INV_M from the game and just use maxvolume in all instances.


I edited the previous post to add some more detail and fix a small mistake.

but I have it in a turn script, so it takes 1 action to catch up and show the correct Status in the panel.

Turnscripts run at the end of every turn; are you using more than one turnscript to do this?
The most common thing people try is having one script to set INV_C to the current value, and then another to set a string attribute based on the current value of INV_C, which is displayed in the status attributes panel.

If this is the case, you could either put those two things into a single script (so you know that INV_C is updated before the string attribute), or put the code that creates the string in a script attribute called game.pov.changedINV_C (which causes Quest to run it automatically and immediately whenever the value of INV_C changes).


newfish = CloneObjectAndMoveHere (original fish)
DoTake (newfish, false)

Is there a way to replace these lines so that they utilise the attribute:
(object.prototype = FISH_Carp)


If this is the case, you could either put those two things into a single script

Yup, I had them in the wrong order in the script... it was updating panel first. Doi!


Is there a way to replace these lines so that they utilise the attribute:
(object.prototype = FISH_Carp)

I'm not sure what you mean here. What do you want it to use that attribute for? If you're cloning the object here, you already know what its prototype is. You would just be doing:

newfish = CloneObjectAndMoveHere (FISH_Carp)
DoTake (newfish, false)

Ok, I get it now, it looked like it was causing a problem but the problem was caused elsewhere. Thanks for the help!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums