Help with limited containers (Simple doubt)

Don't have that much experience with programming but really interested in learning, I have a really simple question (I think)

In my game I want to set up a "portable container" limited to a certain amount of objects and using the limited containers (Backpack) I set up the limit of objects to one and the limit of volume to thirty (just an example), regardless of the amount of objects and volume the limited container never stops the player from adding more objects and keeps on going as normal, I've tried many ways to change it but I just don't get how to properly set up the container

Can provide screenshots if needed, and thanks


Hello.

I made a bare bones example game to test it, and it works as expected for me.


image


image


Do you have any added scripts or anything?


It is worth noting that the put #object1# in #object2# command checks if the second object is a limited container. If you are using some other script to put items in the backpack, you will need to check it manually.

For example, if you have a script which automatically puts objects into the backpack when taken, you would need to change:

MoveObject (obj, backpack)

to

AddToInventory (obj)
do (put, QuickParams ("object1", obj, "object2", backpack))

Thanks for the help, I had been using the MoveObject script to add the items to the inventory and seems like it was the reason the container wasn't working however now I've been trying to use the script by Mrangel like this (Pretty sure I'm not doing it right)

AddToInventory (lantern)
do (put, QuickParams ("object1", lantern, "object2", backpack))

But now I get the following error

Error running script: Error compiling expression 'QuickParams ("Object1", lantern, "object2", backpack)': RootExpressionElement: Cannot convert type 'QuestDictionary`1' to expression result of 'String'

Thanks a lot again


Sorry, my bad. It should be:

AddToInventory (lantern)
do (put, "script", QuickParams ("object1", lantern, "object2", backpack))

This will leave the item in the player's inventory if the backpack is full. If you want to move it somewhere else, you can do something like:

AddToInventory (lantern)
do (put, "script", QuickParams ("object1", lantern, "object2", backpack))
if (not Contains (backpack, lantern)) {
  MoveObjectHere (lantern)
}

which would put it back on the floor instead, displaying only the usual "is full" or "you can't put more objects in" messages.


Thanks a lot and sorry for replying until now, work is driving me crazy

I used the second script you mentioned but now I'm getting a "generic" error

Error running script: Object reference not set to an instance of an object

I tried to check for a way to solve it but I'm not really sure what's wrong with it I'll keep trying to get it done but any help would be really appreciated


I hate to butt in, but Quest is case-sensitive, and I see you wrote Backpack in your first post (not "backpack").

Try changing that in the script.

If that doesn't work, check if the lantern's name is Lantern or lantern, too.

If that doesn't work, mrangel will surely be around sometime soon.


All help is appreciated, all names where the same within the whole script and even tried to change them but I keep getting the same error

Error running script: Object reference not set to an instance of an object

Guess I can do it all over again in the meantime, didn't have that much to begin with and it'll help me practice


If you post your code, we can probably save you from starting over.

Nothing we threw out there worked, but we were just guessing without having seen the code.


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

Support

Forums