Being able to actually interact with items in GUI

Started by xStaH, Wed 16/05/2007 02:11:38

Previous topic - Next topic

xStaH

Hi all,

So I am making a simple game. In my game I wanted to be able to interact with inventory items in the Inventory GUI (the default interact action is to select the inventory item as the active inventory cursor). I spent quite a while searching the forums on how to do this without checking the "run script in inventory" check box and rescripting the whole GUI, and couldn't find much. Eventually I found a quick fix, and I thought I would share it with the community to save others from having to search everywhere, as well as get feed back for improvements.

My goal was to make it appear as the regular interact cursor in graphic and feature.  So here's what I did (remember, I'm a noob, and I figured other noobs could follow this, thus I use a combination of scripting and the graphical style):

1) Go to the cursor menu and make a new cursor.  I called mine "InteractG" (for GUI)

2) In the Global Script, create a new function:

Code: ags

#sectionstart InteractG_Click  //DO NOT EDIT OR REMOVE THIS LINE
    function InteractG_Click(GUIControl *control,  MouseButton button) {
    mouse.Mode = eModeInteractG;
}
#sectionend InteractG_Click  //DO NOT EDIT OR REMOVE THIS LINE


3) On your GUI, create a new button. On the settings box that pops up type "InteractG" in the "Script Name" box, "Run Script" in the "Left Click" box, and "InteractG_Click" in "Click" box.

4) In the "Interactions" menu of your inventory item under "Other Click" insert the command "Run Script" and use code similar to the following:

Code: ags

function inventory5_a() {    // script for Inventory item 5 (Wire): Other click on inventory item
      if (mouse.Mode == eModeInteractG) {
      Display("he has no desire to bend the wire.");  //script whatever you want to happen if you use your new cursor on an item in the GUI
}
}


You may notice a problem.  If you use your new interact cursor on an item and then directly press the ok button on your GUI you new cursor will be the active cursor on your level.  Except it has no function on the actual level and is annoying.  I overcame this by adjusting the following code to the end  "#sectionstart btnInvOk_click"  code.

Code: ags

if (mouse.Mode == eModeInteractG) { //IF THE LAST BUTTON CLICKED WAS THE NEW CURSOR
	  mouse.Mode = eModeInteract; // CHANGE CURSOR TO THE REAL INTERACT


So I hope this helps people. If you see an error or a way to improve this, let me know.  Again, this is a very basic way of working around the problem.

SMF spam blocked by CleanTalk