Clearing Inventory

2924tls
Hi everyone, new here.

I have no clue what I am doing for a lot of things with the Quest online editor.

I've been looking but am still confused about how I would clear the players inventory. I read on another thread that you could change the player object or do a foreach thing, but I really don't know how I'd pull off either.

I tried doing a foreach, but what do I put for loop variable? How do I create that variable and what should it be? Then when I move each object to a container do I use the same variable for that script?

Haven't tried the player object changing thing.

Anyone want to at least point me in the right direction?

Thanks.

HegemonKhan
I'm not that familiar with the gui~editor (as I do most stuff directly with typing in code to the code), but I'll try to help anyways, and hopefully it'll be of help to you:

the 'foreach's' variable is a temporary variable that is used for the 'foreach's' built-in looping capability (as it's getting and using each~every~all of your items in your list or dictionary, aka your 'player.inventory' in this case):

(an in-code example, pretend that our 'inventory' is instead a sports team, for an anology conception)

player.inventory = split ("jim;jeff;joe;john",";")

(temporary~local 'foreach' variable: team_member, you can label~call this variable whatever you want)

foreach (team_member, player.inventory) {
MoveObject (team_member,your_destination_object_name)
}
// this will move the 'jim' object to your destination object, next move the 'jeff' object to your destination object, third 'joe' object, and lastly the 'john' object too. For*EACH* -> it acts upon each~every~all items in your list or dictionary. the built-in foreach's looping capability is for this very purpose, this is done internally by quest: team_member=jim, team_member=jeff, team_member=joe, and lastly team_member=john


You should be able to find~select what you see above, easily within the gui~editor, hopefully:

run as script -> add a script -> ??? -> foreach -> (label for your variable ~ whatever you want to call it, name_of_the_object_that_has_your_list_or_dictionary_attribute.name_of_your_list_or_dictionary_attribute)

run as script -> add a script -> objects -> MoveObject -> (name of object you want to move, name of the object that you want to move your object over to it)

if you want to create a hidden (from the person playing your game) 'storage' object, than just create an object (Type of object: object, ie not a 'room' nor a 'player' type of object) that isn't inside of another object (like not inside of a room object). And, you also got to set it as a 'container' type too.

jaynabonne
First, it would help to know what you mean by "clear the inventory". Do you mean the objects all disappear (go somewhere hidden), or do they get dropped into the current room?

For the latter, you can do this:

foreach(item, ScopeInventory()) {
item.parent = game.pov.parent
}

Basically, "ScopeInventory" returns all items in the inventory. You don't need to create variables - they come into existence when you need them. In this case, it uses "item" in the loop. And it just sets the item's parent to the player's parent - it drops them in the room. If you want them to go somewhere else (for example, a container), you can set the parent to that.

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

Support

Forums