Simple script to test out inventory item combinations - not working

Started by bx83, Sat 15/05/2021 12:26:13

Previous topic - Next topic

bx83

I wrote the below to test all my inventory objects combining with all other inventory objects. This is speed up testing.

Code: ags
  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.

bx83

Okay, tried the following:

Code: ags
  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.

bx83

And cleaned up code:

Code: ags

  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).

bx83


eri0o

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.

bx83

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?

Crimson Wizard

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.

SMF spam blocked by CleanTalk