Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Sat 15/05/2021 12:26:13

Title: Simple script to test out inventory item combinations - not working
Post by: bx83 on Sat 15/05/2021 12:26:13
I wrote the below to test all my inventory objects combining with all other inventory objects. This is speed up testing.

  for (int i=1;i<=Game.InventoryItemCount;i++) {
    player.ActiveInventory=inventory[i];
    for (int j=1;j<=Game.InventoryItemCount;j++) {
      Display("combining object index %s (%d/%d) with %s (%d/%d)",inventory[i].Name, i, Game.InventoryItemCount, inventory[j].Name, j, Game.InventoryItemCount);
      Display("modeusinv interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeUseinv));
      inventory[j].RunInteraction(eModeUseinv);
    }
  }


Always comes up as 1/true interaction available, runs the interaction, nothing happens. Don't know if this is supposed to go to a pre-existing function (of which there are many), or something else, but no useinv ever works or responds. No 'I can't use these objects together' standard programmed response; nothing.
Title: Re: Simple script to test out inventory item combinations - not working
Post by: bx83 on Sun 16/05/2021 04:25:49
Okay, tried the following:

  gInventory.Visible=true;
  Debug(0, 0);
 
 
 
  //use i on j
  for (int i=1;i<=Game.InventoryItemCount;i++) {
   
    InventoryItem *a;
    a = invCustomInv.ItemAtIndex[i];
    Display("a.Name %s",a.Name);
    player.ActiveInventory=a;
    game.inv_activated=a.ID;
   
    Display("inv_active activeinventory is %d",game.inv_activated);
    Display("pl.activeinventory is %d",player.ActiveInventory);
   
    Display("activeinv %d %d",player.ActiveInventory, game.inv_activated);
   
    for (int j=1;j<=Game.InventoryItemCount;j++) {
      Display("combining object index %s (%d/%d) with %s (%d/%d)",inventory[i].Name, i, Game.InventoryItemCount, inventory[j].Name, j, Game.InventoryItemCount);
     
      Display("modeusinv interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeUseinv));
      inventory[j].RunInteraction(eModeUseinv);
      Display("modelookat interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeLookat));
      inventory[j].RunInteraction(eModeLookat);
      Display("modeinteract interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeInteract));
      inventory[j].RunInteraction(eModeInteract);
      Display("modepickup interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModePickup));
      inventory[j].RunInteraction(eModePickup);
      Display("modetalkto interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeTalkto));
      inventory[j].RunInteraction(eModeTalkto);
      Display("modewalkto interaction with %s is %d",inventory[j].Name, inventory[j].IsInteractionAvailable(eModeWalkto));
      inventory[j].RunInteraction(eModeWalkto);
     
    }
  }


Output is:
a.Name Knife
inv_active activeinventory is 2
pl.activeinventory is 0
activeinv 0 2
combining object index Art Notebook (1/144) with Art Notebook (1/144)
modeusinv interaction with Art Notebook is 1
modelookat interaction with Art Notebook is 1
modeinteract interaction with Art Notebook is 0
modepickup interaction with Art Notebook is 0
modewalkto interaction with Art Notebook is 0

etc.

Nothing happens and no functions are run at any point. I'm in the dark, can anybody help? All I want to is simulate: item A being ActiveInventory, player clicks mouse on item B, iB_useinv() runs, it goes on to next combination.
Title: Re: Simple script to test out inventory item combinations - not working
Post by: bx83 on Sun 16/05/2021 04:35:55
And cleaned up code:


  InventoryItem *a;
  InventoryItem *b;
 
  //use i on j
  for (int i=0;i<=Game.InventoryItemCount;i++) {
    a = invCustomInv.ItemAtIndex[i];
   
    for (int j=0;j<=Game.InventoryItemCount;j++) {
      b = invCustomInv.ItemAtIndex[j];

      player.ActiveInventory=a;
      Display("player.ActiveInventory.Name is %s while i is %d",player.ActiveInventory.Name, i);
     
      Display("combining object index %s (%d/%d) with %s (%d/%d)",a.Name, i, Game.InventoryItemCount, b.Name, j, Game.InventoryItemCount);
     
      Display("modeusinv interaction with %s is %d",b.Name, b.IsInteractionAvailable(eModeUseinv));
      b.RunInteraction(eModeUseinv);
    }
  }


...and nothing happens at b.RunInteraction (though interaction is available).
Title: Re: Simple script to test out inventory item combinations - not working
Post by: bx83 on Sun 16/05/2021 08:27:51
There's really nobody who can shed some light on this?
Title: Re: Simple script to test out inventory item combinations - not working
Post by: eri0o on Sun 16/05/2021 09:31:07
How do you handle using items in your game? I advise calling the function directly on your global script.

RunInteraction has some requirements that I don't think will work in your case.
Title: Re: Simple script to test out inventory item combinations - not working
Post by: bx83 on Sun 16/05/2021 09:48:10
Okay - do some of the requirements use GUIs and screen interactions? I was just trying to figure out how to do it manually.
Could you explain?
Title: Re: Simple script to test out inventory item combinations - not working
Post by: Crimson Wizard on Sun 16/05/2021 11:39:30
I believe RunInteraction is similar to ChangeRoom etc: it queues the command and runs it only after your script function ends.
There's also a very small limit for queued commands, and apparently no error is given if engine reaches this limit.

This kind of commands are meant to be run one at a time.