Backpack Idea....[SOLVED]

Anonynn
Alright, so originally I had a problem with a "backpack" object, but it seems like it still counts things as children on the player even when the parent (backpack) is carrying the items, so I decided to just nix the whole premise because it's just causing way too many problems. I did come up with a new idea though.

I was thinking of creating an "Attribute" on the player.object called "weight" and making it an integer of 2. Then equipping the backpack item increases that by like 13 making it a total of 15. Then I could have each object the player can carry -1 weight and when it hits "1" have a changedweight attribute that states their inventory is full. Then I could use other containers later on and have them add to the carry weight.

Does this make sense or sound doable?

Zephyrus Scary
There's already an attribute for that called "maxobjects". You must activate it in the game > Features tab, called "Inventory limits". Then, you can simply add to the backpack > Inventory tab, add a script to both "after taking" and "after dropping": "Set variable player.maxobjects = player.maxobjects + 13" or "= player.maxobjects - 13" (remember to add the minus to the drop action, or your players will be able to get unlimited inventory space!). However, this means the player won't be able to pick up the backpack if the inventory is already full. Better, IMHO, is the volume and maxvolume attributes, as you can set every object's volume to any integer, even zero (so that the object is always takeable, even when maxobjects would say otherwise), so it can be picked up, even when the player has an otherwise full inventory, AND you have much better control over what the player can carry and when, whereas the maxobjects attribute always counts every object as "1", no matter what. Only downside is that you have to remember to set every takeable object's volume, as it is initially set at zero...

XanMag
It seems like it would work, but what happens if the player is carrying the backpack but not equipping it? And then, what if the player tries to pick up more stuff when the backpack is carried but not equipped?

I think I had a similar situation in X2. Instead of changing the weight and fiddling with all of that, could you just increase the carrying capacity of the player when the object is picked up and make the container 'undroppable'? When picking up a different container, you could then discard the old one so that the player is not carrying around a bunch of containers. Say, your first item is a knapsack. When added to inventory, you can increase the player inventory limit from 2 to 4. Later you find a backpack. When the player picks this up, you could print a message like "Great, this is much better than that knapsack. You could carry more things in it! You discard the old knapsack." Then, add backpack to inventory, remove object knapsack, and increase inventory limits to 10. Of course, you would have to make the container you are carrying around unable to be dropped. I also had to add a "remove container" command (with an If (player has flag (which was set when picking up the container))/Else script) and a message indicating that you didn't need to remove it until you found a larger container to replace it.

Also, what happens if you have 10 items in your container that is in your inventory and you 'get object' from the container which is in your inventory. I think it will remove the object from the container and add it to your player - which I THINK ignores the player inventory limits. What if some smart ass tries to get all 10 objects from the container and they are added to the player inventory. Then... they find a different container to replace the old one but can't pick it up because the player is carrying too many items? I'm not sure if that makes sense, but I feel like it happened in X2.

So... in short, I think you better be damn certain that carrying a container to carry your stuff is well worth it. lol

Also, does anyone know WHY items added to a container in your inventory appear to list the objects as children of the player? It would be nice to be able to carry around ONE item in your inventory with hidden children AND then be able to look at that one item and see the contents of it. I did some serious tinkering with the 'inventory' command and a container backpack. I couldn't get the items to disappear in the inventory pane OR when I typed 'i' to check my inventory. They are always there no matter what it seems.

@Neonayon, did you start a thread somewhere on this?

@Zeph, Won't you still have the issue of the children of the backpack being listed as a a child of the player and NOT the backpack?

Pardon me... I'm tired!

Sorry to ramble, but just thinking the last hour or two out loud!

Anonynn
I dunno, I just ran into a ton of problems trying to separate the backpack carry from the player carry limits so I'd rather completely control the variables :)

UPDATE:

I decided to try and combine ideas here. I have multiple carry items some can be worn like the backpack and some can be carried like a brown sack.

The wearable objects add volume to the player's maxvolume limit when worn and subtract it when it isn't. The unwearable items, add to the player's volume when simply taken and then subtract from it when dropped. We'll see how that works out. I may add a subtract to all other items when picked up...like -1 player.maxvolume or something and then +1 when that item is used or dropped. That way the player always knows how much more they can carry. In the player description you write:

Max Carry (or whatever): {player.maxvolume}.

Hope that helps other people!

Zephyrus Scary
@XanMag,

Neon didn't say anything about making the extra objects move into the bag. In the interest of science, however, I doodled a bit, and found a little trick:

1. Make your backpack a container.

1-optional. Checkmark "Hide children ..." if you don't want items in the bag to be listed in inventory.

2. Add a function, like "takeinbackpack".

3. Add parameter "object" (w/o quotes) to "takeinbackpack".

4. Add script "If... player is carrying object: object: backpack"

5. "Then: Move object [expression:] object to [object:] backpack"

6. On every takeable object, add script "call function" to "after taking". Call function "takeinbackpack" with parameter as the object's name.

This is only barely workable, though, as I have no idea how to refer to "If... object is full" or whatever, as even making the backpack a limited container doesn't prevent the object from being added to the backpack.

EDIT: Also, this reitroduces the maxobjects problem. If the bag contains too much volume of objects for the player's current maxvolume, it cannot be picked up...

EDIT2: Roundabout fix to said problem:

Container Fix.png


EDIT3: Perhaps the final solution? still requires a custom attribute, but better than rewriting the whole "take" verb!

Container solution.png


Remember to add the new parameter to every takeable object. Ideally, the parameter should be equal to the volume!

Also, to the "remove... from ..." command, add "Set variable object_two.filling = object_two.filling - object_one.volume"

Anonynn
I figured something out. I'll open the thread again if it doesn't end up working :)

Thanks Zeph and Xan for your input!

HegemonKhan
There's also Object List Attributes, their 'ListCount', and the 'foreach' Function:

http://docs.textadventures.co.uk/quest/ ... lists.html

http://docs.textadventures.co.uk/quest/scopes.html
http://docs.textadventures.co.uk/quest/ ... jects.html
http://docs.textadventures.co.uk/quest/ ... jects.html
http://docs.textadventures.co.uk/quest/ ... ldren.html

http://docs.textadventures.co.uk/quest/ ... reach.html

http://docs.textadventures.co.uk/quest/ ... count.html
http://docs.textadventures.co.uk/quest/ ... tains.html

---------

also, you can create two Attributes, a 'maximum' and 'current' Attribute:

(by having 'current/maximum' Attributes, this allows for you to control/handle/manipulate it, but it also means that you have to do this, lol)

if (backpack.current_capacity < backpack.maximum_capacity) {
// script to move 'whatever' Object into the backpack
backpack.current_capacity = backpack.current_capacity + 1
} else {
msg ("The backpack is full.")
}


let's say you discover some means that increases your maximum capacity by 100 in the game:

backpack.maximum_capacity = backpack.maximum_capacity + 100


which, will now be the new maximum capacity for your checking script above: '...backpack.current_capacity < backpack.maximum_capacity) {...'

-------

using Lists:

if (ListCount (GetDirectChildren (backpack)) < backpack.maximum_capacity) {
// script to move 'whatever' Object into the backpack
} else {
msg ("The backpack is full.")
}


foreach (object_variable, GetDirectChildren (backpack)) {
// whatever script(s) to act upon each/every/all direct child Objects in your parent 'backpack' Object, for example:
// (I used 'object_variable' as the name-label, but you can use whatever you want, this will represent each/every/all direct child Objects in your 'backpack' parent Object)
// msg (object_variable.alias)
// the above will display the aliases of all the direct child objects in the 'backpack' parent object
}


also, instead of using 'GetDirectChildren()' Function, you can use 'GetAllChildObjects()' Function, and/or there's always the 'AllObjects()' Function too. Also, there's the 'Scope ' Functions too (see links above).

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

Support

Forums