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.
//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:
//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?
Try
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...
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.