activate walkable areas

Started by JpGames, Tue 15/05/2007 04:45:59

Previous topic - Next topic

Ashen

Try:
Code: ags

if (player.ActiveInventory != null) Display ("Item %d used on object 1.", player.ActiveInventory.ID);
else Display("No active item");


Just to double check.

However, the original code (this post, a few up) seemed like it was in the 'Use inventory on' interaction - is it possible for that to run with no Active Inventory item? That would certainly explain both the null pointer error and why the code wasn't running in the first place, I just didn't think it could happen...

I wasn't sure about the player.ActiveInventory.ID bit, but I tested before posting and THAT works, so it must be the interaction somehow running with no ActiveItem.
I know what you're thinking ... Don't think that.

Khris

Yeah, I should have been clearer, of course the .ID bit isn't wrong by itself, just calling it while ActiveInventory is null will throw an error.

But, as you've already said, it shouldn't be null in this case.

EDIT: I've done some testing:
-Setting ActiveInventory to an InvItem will automatically change mouse.Mode to eModeUseinv (if the player possesses the item, otherwise the game crashes).
-Setting mouse.Mode to eModeUseinv doesn't have any effect if ActiveInventory is null.
-I was able to replicate the error (i.e. calling "Use inv on object" while ActiveInventory==null), but only by directly calling either ProcessClick(255, 123, eModeUseinv); or oBottle.RunInteraction(eModeUseinv);

Conclusion: Both ProcessClick and RunInteraction shouldn't be called with anything else than mouse.Mode, because in that case mouse.Mode can't be eModeUseinv while ActiveInventory==null.

Further conclusion: Some faulty code is used, probably in on_mouse_click.

WolfBlacker

I'm using the default game. And I used the code that Ashen gave - it shows up "No active item".

Khris

Are you using any modules or did you copy&paste any other stuff from the forums into your game?
Did you change anything in the cursor pane?

And please post the on_mouse_click from the global script.

WolfBlacker

#24
No, I'm not using anything, no modules or script from other forums. And I didn't changed anything.

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE

Khris

This keeps getting weirder.

Just to make sure:
When you are clicking on the object, your cursor is some inventory item graphic, right? It's inv item Nr. 3, correct? No white hand or pointer or something like that?
And directly after the click, you get "No active item"?

WolfBlacker

Yes, yes, no, yes. And...
Umm...I don't know what was it, but I've checked the "Don't use inventory graphics as cursors" in the general settings, it still shows up the "No active item" but suddenly...it works O.O'' I've added one walk-behind and I'm testing it again. An error when I've used item on object. Great, what this time? "In Global script (line 60)
Error: ObjectOn: invalid object specified)"
And in global I didn't changed ANYTHING.

Khris

#27
By "it works", you mean that now the walkable area is turned back on?
ObjectOn is old code, you shouldn't be using that.
Line 60 contains ProcessClick, so the actual erroneous line is in the room's script.

I'd really like to take a look at the game, could you upload it and PM me the link?

Edit: Alright, I found the problem.
You're removing the inventory item using an action, then using a RunScript-action to enable the walkable area.
1. Removing the active inv item will change player.ActiveInventory to null.
2. You don't need to check for the correct item again because the RunScript-action is already a child action of the Conditional checking which item was used.

We didn't have any idea that you're using all those actions beside the RunScript ones.
Btw. that's the reason why the second error is thrown in the global script; you aren't trying to turn on the object in the room script but using an action. You need to change the number to 3. The object is the fourth one, but object counting starts at 0.

I'd recommend to switch over to scripting. Using the Interaction editor is tedious and error-prone.

And you don't need a dialog just to make the player say something.
If you want to keep using the interaction editor commands, use "Game - Display a message" and in the Message Editor window, select the Character where it says "Display message as:".

Again, I'd really recommend to do it with scripting.
It's as easy as:
Code: ags
  player.Say("Blah.");

WolfBlacker


Khris


SMF spam blocked by CleanTalk