Custom inventory scripting difficulties (SOLVED)

Started by simulacra, Mon 21/02/2005 00:29:11

Previous topic - Next topic

simulacra

I am working on a custom inventory and have run into some diffculties. I want the inventory to be modal (I have some timed events that I do not want to happen when the inventory is displayed as the player is occupied with that) and I want to have a lucas-arts descriptive tag line in that window.

Question one is: how do I prevent timed events from occuring while being able to update a tag line with repeatedly_execute?

I want the following commands to be available: Look, Select, Combine and Close. No problem with Look and Combine (Left click: Set cursor mode). However, when clicking the inventory after choosing Select, I want the game to close the inventory window and display a Use inv cursor with the clicked item. Problem is, when having a modal window, on_mouse is disabled and interface_click does not seem to recognise LEFTINV. I'm stuck.

Question two is: how do I do this without having a non-modal dialog with the game running in the background?

Rui 'Trovatore' Pires

You could always make a check in rep_execute. If timer is expired check to see if the GUI is on. If not, execute stuff. If so, set the timer to 1. It will keep checking untill the GUI is off. This should make it work on non-modal.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

simulacra

Nice suggestion. However, this would require lots of changes in numerous room scripts using rep_exec, right?

Radiant

No, you can put it in the global script.

Scorpiorus

Quote from: simulacraProblem is, when having a modal window, on_mouse is disabled and interface_click does not seem to recognise LEFTINV. I'm stuck.
Yep, that's because a Popup modal GUI pauses the game and there is a default code within on_mouse_click (at the top of it) to prevent anything happen if the game is paused.

So, handling inventory clicks before it should do the trick:

function on_mouse_click(int button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT

Ã,  if (button == LEFTINV) {

Ã,  }

Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  }


Quote from: simulacraQuestion one is: how do I prevent timed events from occuring while being able to update a tag line with repeatedly_execute?
Yeah, you can use built-in timers, as Rui suggested.
For other things such as timer-like variables you can check if the game is paused before updating them:

function repeatedly_execute() {

if (IsGamePaused()==0) {
   timer++;
}

// updating any tag lines here (regardless of whether the game is paused (ex: Popup modal GUI is on) or not)

}

simulacra

Right, I have tried this in on_mouse, before the if (IsGamePaused() == 1) (with strange results):

if (button == LEFTINV)   {
   if (GetCursorMode()==2)   {
            GUIOff(7);
            }
   RunInventoryInteraction(game.inv_activated, GetCursorMode());
         }

When using the Look command, it works as usual but when using Use, I get a Talk cursor. Adding SetMouseCursor(4); after GuiOff turns it into a Use cursor, not a Use Inv cursor as I was hoping for.

Scorpiorus

QuoteAdding SetMouseCursor(4); after GuiOff turns it into a Use cursor, not a Use Inv cursor as I was hoping for.
Yeah, you have to set an active inventory item for the UseInv cursor to appear:


if (button == LEFTINV)Ã,  Ã, {
   if (GetCursorMode()==2)Ã,  Ã, {
      GUIOff(7);
      SetActiveInventory(game.inv_activated);
   } else {
Ã,  Ã,  Ã,  Ã,  RunInventoryInteraction(game.inv_activated, GetCursorMode());
   }

}

simulacra

#7
I still get a Look cursor when the GUI closes. I have even tried this with the same result:

if (button == LEFTINV)   {
   if (GetCursorMode()==2)   {
      GUIOff(7);
      SetActiveInventory(game.inv_activated);
      SetCursorMode(MODE_USEINV);
   } else {
        RunInventoryInteraction(game.inv_activated, GetCursorMode());
   }

}

Seems the SetCursorMode(MODE_USEINV); is disregarded somehow.

EDIT: Solved the issue using incredibly bad coding. Even though it works, it does not please my sense of aesthethics.

if (button == LEFTINV)   {
   if (GetCursorMode()==2)   {
      GUIOff(7);
      SetActiveInventory(game.inv_activated);
      SetNextCursorMode();
      SetNextCursorMode();
      SetNextCursorMode();
   } else {
        RunInventoryInteraction(game.inv_activated, GetCursorMode());
   }

}

Scorpiorus

#8
Quoteif (GetCursorMode()==2)Ã,  Ã, {
Ã,  Ã,  Ã,  GUIOff(7);
Ã,  Ã,  Ã,  SetActiveInventory(game.inv_activated);
Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã, }

Considering that code solves the problem I'd say it is possible the cursor mode is as well changed with SetNextCursorMode() somewhere else.

What's the complete code of on_mouse_click?
Do you have any of cursor changing commands within repeatedly_execute?
Other primarily candidates to look into include: on_event, room's repeatedly execute, room's on_mouse_click.


[EDIT]:

The following test code should make it clear whether the cursor mode is indeed overrided afterwards:

if (GetCursorMode()==2)Ã,  Ã, {
   GUIOff(7);
   SetActiveInventory(game.inv_activated);
   Wait(1); //update just in case
   Display("pause: what's the mode here?");

} else {
   RunInventoryInteraction(game.inv_activated, GetCursorMode());
}

simulacra

I found some obscure code in the on_mouse routine, referring to GetGlobalInt(100). I do not know what it was doing there, but replacing the inte check with an actual check of the mouse button made the day.

Thank you everyone for your help!

SMF spam blocked by CleanTalk