I want AGS to check if there's a currently active inventory item (SOLVED).

Started by Mugs, Tue 14/07/2009 01:04:40

Previous topic - Next topic

Mugs

My game keeps crashing and I know why.  However, I don't know how to fix the problem.

In my game, I want the graphic of the currently active item to change if i press on the look button.
If no item is active however,  the game will crash.


Code: ags

//Somewhere in GlobalScript.asc

function blook_Click(GUIControl *control, MouseButton button) { 
mouse.Mode = eModeLookat;
inventory[game.inv_activated].Graphic = 78;
}


I tried doing the following,  but it did not work:

Code: ags

//Somewhere in GlobalScript.asc

function blook_Click(GUIControl *control, MouseButton button) { 
mouse.Mode = eModeLookat;
     
      if (game.inv_activated != null){
      inventory[game.inv_activated].Graphic = 78;
      }
}


I get "Type mismatch: cannot convert 'int' to 'null*'"

Is there a way to make AGS check if there's a currently active item?



Cool stuff I found out: Men are four times more likely to be struck by lightning than women.  Wow, really? [dirty joke] Maybe this has to do with the fact that us men have "lightning rods"? [/dirty joke]

GuyAwesome

Try
Code: ags

  if (player.ActiveInventory != null) {


game.inv_activated is: a) an int value, not an InventoryItem (the ID of the Item), and so can't be null (-1 might work, though); and b) the last item CLICKED ON, not the current 'active' Item (I think it includes 'Look At Item', 'Talk To Item', etc, interactions).
(Pre-v2.72, player.activeinv is the way to go...)

EDIT:
Alternatively, the method you already have for referencing the Item - inventory[game.inv_activated] - can be null, but as I said isn't actually the ACTIVE Item, just the last clicked...

Mugs

Quote from: GuyAwesome on Tue 14/07/2009 01:23:14
game.inv_activated is: a) an int value, not an InventoryItem (the ID of the Item), and so can't be null (-1 might work, though); and b) the last item CLICKED ON, not the current 'active' Item (I think it includes 'Look At Item', 'Talk To Item', etc, interactions).
(Pre-v2.72, player.activeinv is the way to go...)

Alternatively, the method you already have for referencing the Item - inventory[game.inv_activated] - can be null, but as I said isn't actually the ACTIVE Item, just the last clicked...

Thanks to your help I was able to figure it out.  I tried using -1 like you suggested and that didn't work.  Then I tried using 0 and it worked! :)

Player.ActiveInventory != null wouldn't have worked because by "active"  I really meant "last clicked on" (I just didn't think of it that way).

Anyways,  thanks a bunch GuyAwesome.
Cool stuff I found out: Men are four times more likely to be struck by lightning than women.  Wow, really? [dirty joke] Maybe this has to do with the fact that us men have "lightning rods"? [/dirty joke]

SMF spam blocked by CleanTalk