SOLVED: Reset Room: Inventory

Started by barefoot, Wed 05/01/2011 17:09:42

Previous topic - Next topic

barefoot

Hi

I have an issue regarding Reset Rooms... My Play button is set to Reset the starting room (1) and go to that Room, this works fine.

But, on the game ending the player is given the opportunity to play the game again.

The problem is the inventory is still there in Room 1...

What would be the best way to have no inventory if playing the game again?

So far I did this, though it seems there must be an easier way:

Code: ags

   cleech.LoseInventory(iPoster);
      cleech.LoseInventory(iknife);
         cleech.LoseInventory(idoc);
            cleech.LoseInventory(ihair);
               cleech.LoseInventory(icsibag);
                  cleech.LoseInventory(iprint);
                     cleech.LoseInventory(ibrush);
                        cleech.LoseInventory(iscalpel);
                           cleech.LoseInventory(ispray);
                              cleech.LoseInventory(ineedle);
                                 cleech.LoseInventory(idna);
                                     cleech.LoseInventory(iphoto);
                                         cleech.LoseInventory(idisk);
                                              cleech.LoseInventory(iid);
                                                 cleech.LoseInventory(icsibag1);
                                                    cleech.LoseInventory(idisguise);
                                                       cleech.LoseInventory(icordainates);
                                                          cleech.LoseInventory(idis);
                                                             cleech.LoseInventory(inote2);
                                                                cleech.LoseInventory(ikey2);
                                                                   cleech.LoseInventory(ilocation);


cheers for all advice

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Matti

I think there's an easier way to delete all inventory items, but it seems you're confusing something here:

The ResetRoom command just resets the room - data, objects, scripts. Inventory items have nothing to do with that. What you're looking for is RestartGame();

Btw: You have a strange way of writing down the script, I noticed that earlier ;)

Gilbert

This is answered, but there actually is a way to do that kind of losing item... thing with a simple loop. Just do something like:
Code: ags

  int ii=0;
  while(ii<Game.InventoryItemCount){
    cleech.LoseInventory(inventory[ii]);
    ii++;
  }

barefoot

Hi

thank you both  :=

barefoot
I May Not Be Perfect but I Have A Big Heart ..

monkey0506

To simplify the process of having a character lose all their inventory items (again noting that this is already solved, and essentially reproducing GG's code), you could also stick it in an extender method, like so:

Code: ags
// Script.ash
import function LoseAllInventory(this Character*);

// Script.asc

function LoseAllInventory(this Character*) {
  int i = 1; // note that inventory items are indexed from 1 not 0 (unlike most other things!)
  while (i <= Game.InventoryItemCount) {
    this.InventoryQuantity[i] = 0;
    i++;
  }
  UpdateInventory();
}


I used the InventoryQuantity array directly because it's presumably faster to do this and only update the inventory once when iterating all the inventory items (especially if you have a lot of them). Also, inventory items are indexed from 1-Game.InventoryItemCount not 0-(Game.InventoryItemCount - 1), so I fixed that. But with this you could then simply call:

Code: ags
cleech.LoseAllInventory();


;)

SMF spam blocked by CleanTalk