Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Wed 05/01/2011 17:09:42

Title: SOLVED: Reset Room: Inventory
Post by: barefoot on Wed 05/01/2011 17:09:42
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:


  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

Title: Re: Reset Room: Inventory
Post by: Matti on Wed 05/01/2011 18:13:54
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 ;)
Title: Re: Reset Room: Inventory
Post by: Gilbert on Wed 05/01/2011 18:58:57
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:

 int ii=0;
 while(ii<Game.InventoryItemCount){
   cleech.LoseInventory(inventory[ii]);
   ii++;
 }
Title: Re: Reset Room: Inventory
Post by: barefoot on Wed 05/01/2011 19:08:35
Hi

thank you both  :=

barefoot
Title: Re: SOLVED: Reset Room: Inventory
Post by: monkey0506 on Thu 06/01/2011 03:30:23
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:

// 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:

cleech.LoseAllInventory();

;)