I have the default template and it is perfect for what I'm doing, however, I need an "interact" icon in the inventory like the old Sierra games had. I didn't understand the whole GUI thing. Can anyone help?
Jonathan Grant
Check out this tutorial, it should help:
http://www.digitalmindstudio.ch/script.php?id=4
I read the tutorial but am still confused.Ã, Here's the script:
if (interface == ICONBAR) {
Ã, Ã, if (button == 4) {Ã, // show inventory
Ã, Ã, Ã, show_inventory_window();
Ã, Ã, }
Ã, Ã, else if (button == 5) {Ã, Ã, // use selected inventory
Ã, Ã, Ã, if (character[ GetPlayerCharacter() ].activeinv >= 0)
Ã, Ã, Ã, Ã, SetCursorMode(4);
Ã, Ã, }
Ã, Ã, else if (button == 6)Ã, Ã, // save game
Ã, Ã, Ã, SaveGameDialog();
Ã, Ã, else if (button == 7)Ã, Ã, // load game
Ã, Ã, Ã, RestoreGameDialog();
Ã, Ã, else if (button == 8)Ã, Ã, // quit
Ã, Ã, Ã, QuitGame(1);
Ã, Ã, else if (button == 9)Ã, Ã, // about
Ã, Ã, Ã, Display("Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2003 Chris Jones");
Ã, }Ã, // end if interface ICONBAR
Ã, if (interface == INVENTORY) {
Ã, Ã, // They clicked a button on the Inventory GUI
Ã, Ã,Â
Ã, Ã, if (button == 1) {
Ã, Ã, Ã, // They pressed SELECT, so switch to the Get cursor
Ã, Ã, Ã, SetCursorMode (MODE_USE);
Ã, Ã, Ã, // But, override the appearance to look like the arrow
Ã, Ã, Ã, SetMouseCursor (6);
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, if (button == 2) {
Ã, Ã, Ã, // They pressed LOOK, so switch to that mode
Ã, Ã, Ã, SetActiveInventory(-1);
Ã, Ã, Ã, SetCursorMode(MODE_LOOK);Ã,Â
Ã, Ã, }
Ã, Ã, if (button == 3) {
Ã, Ã, Ã, // They pressed the OK button, close the GUI
Ã, Ã, Ã, GUIOff (INVENTORY);
Ã, Ã, Ã, SetDefaultCursor();
Ã, Ã, }
Ã, Ã, if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
Ã, Ã, Ã, // scroll down
Ã, Ã, Ã, game.top_inv_item = game.top_inv_item + game.items_per_line;
Ã, Ã, }
Ã, Ã, if ((button == 5) && (game.top_inv_item > 0)){
Ã, Ã, Ã, // scroll up
Ã, Ã, Ã, game.top_inv_item = game.top_inv_item - game.items_per_line;
Ã, Ã, }
Ã,Â
Ã, }
What should it be instead?
Jonathan Grant
Go to function show_inventory_window in the global script. Read the comments there (//text here) and it will tell you that you have to delete a certain part to use a custom inventory window.
I'm still so lost. I don't need or want it any different than the default inventory gui, I just need an "interact" button on it (using the default hand icon image). Would it be possible for someone to give me a "dummies" step-by-step guide to doing this that I can understand? Either that or could someone just take the code I pasted above, make the necessary changes (should be really quick and easy, right?) so I can just paste the new code into it?
Also, I'm not seeing the inventory item selected showing up in the window at the top of the screen nor will it show up as the cursor. The cursor is the same default bag image no matter which is selected.
anyone? :(
About the Inventory items not showing up as cursor:
On the General settings panel, make sure 'Don't use inventory graphics as cursors' isn't checked. Sometimes it randomly checks itself.
About the interact button:
Do you just want the existing interact button (the arrow) to have the hand graphic, or do you want a whole new option (e.g to open a box, read a book, etc)?
Thanks Ashen! I'm wanting to add a whole new button just like you described.
Jonathan Grant
By default, the 'USE' interaction only sets the active inventory item, so you'll need to pick another mode to use. I suggest making a new mode, 'INVUSE' - so:
Ã, Ã, 1. Go to the 'Cursors' window of the AGS editor, and select the line that says Cursor 8: USERMODE1 (or something like that).
Ã, Ã, 2. In the 'Cursor name:' box rename it to INVUSE. (This isn't totally necessary, but helps you to keep track)
Ã, Ã, 3. Change the cursor image. Default 'USE' cursor is sprite 2057, in the 'Defaults' folder.
Now you need to add this to the Invetory GUI, so:
Ã, Ã, 4. Go to the GUIs window, and select the INVENTORY GUI.
Ã, Ã, 5. Add a new button, sprite number 2046 in the 'Defaults' folder.
Ã, Ã, 6. Set the Left Click interaction to 'Set Cursor Mode', and 'New Mode Number' to 8.
Ã, Ã, (You could do this with scripting, but it's a little more complicated, and not really necessary.)
Now, like Goot said, you need to tell AGS to use this GUI instead of the in-built one:
Ã, Ã, 7. Open the script editor, and scroll near the top until you find this:
function show_inventory_window () {
Ã, // This demonstrates both types of inventory window - the first part is how to
Ã, // show the built-in inventory window, the second part uses the custom one.
Ã, // Un-comment one section or the other below.
Ã,Â
Ã, // ** DEFAULT INVENTORY WINDOW
Ã, InventoryScreen();
/*Ã,Â
Ã, // ** CUSTOM INVENTORY WINDOW
Ã, GUIOn (INVENTORY);Ã,Â
Ã, // switch to the Use cursor (to select items with)
Ã, SetCursorMode (MODE_USE);
Ã, // But, override the appearance to look like the arrow
Ã, SetMouseCursor (6);
*/
}
Ã, Ã, 8. Change it to this:
function show_inventory_window () {
Ã, GUIOn (INVENTORY);Ã,Â
Ã, // switch to the Use cursor (to select items with)
Ã, SetCursorMode (MODE_USE);
Ã, // But, override the appearance to look like the arrow
Ã, SetMouseCursor (6);
}
You should now have an Inventory GUI with a Hand Icon on it. To make this mode work on inventory items:
Ã, Ã, 9. Open the item's interaction editor, and choose 'Other click on inventory item'.
Ã, 10. Chose 'Run Script', then 'Edit Script', then add this to the script:
Ã, Ã, Ã, if (GetCursorMode() == 8) {
Ã, Ã, Ã, Ã, //whatever you want to happen
Ã, Ã, Ã, }
That should be it. Hope it helps.
Thanks for the help but I think what it shows is a little different than what you said.Ã, I pasted above what it says.Ã, Would it be possible to just copy what I pasted and paste it in your reply with those changes made?
I tried what you suggested and when I tried to test the game it said the "inventory window" command was already named by something else and there was an error.Ã, Here is what I had done:
if (interface == ICONBAR) {
Ã, Ã, if (button == 4) {Ã, // show inventory
Ã, Ã, Ã, function show_inventory_window () {
Ã, GUIOn (INVENTORY);Ã,Â
Ã, // switch to the Use cursor (to select items with)
Ã, SetCursorMode (MODE_USE);
Ã, // But, override the appearance to look like the arrow
Ã, SetMouseCursor (6);
Ã, Ã, }
Ã, Ã, else if (button == 5) {Ã, Ã, // use selected inventory
Ã, Ã, Ã, if (character[ GetPlayerCharacter() ].activeinv >= 0)
Ã, Ã, Ã, Ã, SetCursorMode(4);
Ã, Ã, }
Ã, Ã, else if (button == 6)Ã, Ã, // save game
Ã, Ã, Ã, SaveGameDialog();
Ã, Ã, else if (button == 7)Ã, Ã, // load game
Ã, Ã, Ã, RestoreGameDialog();
Ã, Ã, else if (button == 8)Ã, Ã, // quit
Ã, Ã, Ã, QuitGame(1);
Ã, Ã, else if (button == 9)Ã, Ã, // about
Ã, Ã, Ã, Display("Lamp of Learning's SNU Adventure by Jonathan Grant et. al. 2004");
Ã, }Ã, // end if interface ICONBAR
Ã, if (interface == INVENTORY) {
Ã, Ã, // They clicked a button on the Inventory GUI
Ã, Ã,Â
Ã, Ã, if (button == 1) {
Ã, Ã, Ã, // They pressed SELECT, so switch to the Get cursor
Ã, Ã, Ã, SetCursorMode (MODE_USE);
Ã, Ã, Ã, // But, override the appearance to look like the arrow
Ã, Ã, Ã, SetMouseCursor (6);
Ã, Ã, }
Ã, Ã,Â
Ã, Ã, if (button == 2) {
Ã, Ã, Ã, // They pressed LOOK, so switch to that mode
Ã, Ã, Ã, SetActiveInventory(-1);
Ã, Ã, Ã, SetCursorMode(MODE_LOOK);Ã,Â
Ã, Ã, }
Ã, Ã, if (button == 3) {
Ã, Ã, Ã, // They pressed the OK button, close the GUI
Ã, Ã, Ã, GUIOff (INVENTORY);
Ã, Ã, Ã, SetDefaultCursor();
Ã, Ã, }
Ã, Ã, if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
Ã, Ã, Ã, // scroll down
Ã, Ã, Ã, game.top_inv_item = game.top_inv_item + game.items_per_line;
Ã, Ã, }
Ã, Ã, if ((button == 5) && (game.top_inv_item > 0)){
Ã, Ã, Ã, // scroll up
Ã, Ã, Ã, game.top_inv_item = game.top_inv_item - game.items_per_line;
Ã, Ã, }
Ã, }
You didn't have to make any changes in the if (interface == ICONBAR) part of the script.
The code I posted is further up the global script, it's a function that tells AGS whether to use the in-built inventory window, or the INVENTORY GUI. So, in what you pasted, change:
Ã, Ã, if (button == 4) {Ã, // show inventory
Ã, Ã, Ã, function show_inventory_window () {
Ã, GUIOn (INVENTORY);Ã,Â
Ã, // switch to the Use cursor (to select items with)
Ã, SetCursorMode (MODE_USE);
Ã, // But, override the appearance to look like the arrow
Ã, SetMouseCursor (6);
Ã, Ã, }
back to
Ã, Ã, if (button == 4) {Ã, // show inventory
Ã, Ã, Ã, show_inventory_window ()
Ã, Ã, }
and make the changes to the function script - it starts around line 17 of the global script, and should look exactly as I showed, since I just copy & pasted it. Sorry if I was unclear in my last post, hopefully it makes more sense this time.
Okay, thanks for the explanation. I changed that in the global script. I can't seem to find "other click on inventory" in the gui though and I'm unclear exactly where to paste
if (GetCursorMode() == 8 ) {
//whatever you want to happen
}
Also, do I need to put anything in the brackets there or can I make it so that it will do one of the not already used interaction options (like talk to) in the inventory interaction editor?
EDIT - Also, I just tested the game to see how it looks and the inv sprites are all over the place instead of equally spaced like in the default gui. The background of where the items are is also not black like the default gui. Why the difference? Is there not a way to ONLY change the addition of the hand button without changing all that other stuff?
Edit2 - Also, the new GUI won't allow you to click on ANYTHING so the game basically locks up at that point. Help!
Thanks again for your patience!
Jonathan Grant
1. 'other click on inventory' isn't in the GUI section, it's in the Inventory Items interactions.
A. Open the item's interaction editor, and choose 'Other click on inventory item'.
B. Chose 'Run Script', then 'Edit Script', then add the if (GetCursorMode() == 8 ) script.
2. Do you need to put anything in which brackets? If you mean the ones in GetCursorMode(), then no you don't. You will need to replace the line
//whatever you want to happen
with the scripting for the interaction you want to run. For example:
if (GetCursorMode() == 8 ) {
RunDialog (1);
}
3. The spacing may be due to the size of your inventory item sprites. What size are you using? By default, AGS spaces them based on a 40x22 pixle sprite. You may want to look into the SetInvDimentions command. I have no idea why the background colour changed. I don't think there is an other way to add the button you want, with out going through all this, but maybe a more experienced AGSer knows one.
4. I also can't think why this is, unless the button assignments have gotten messed up. Check that they're all set to 'Run Script' - except the Hand button, which should be set to 'Set cursor mode' - and check the object numbers against against the inventory script:
if (interface == INVENTORY) {
// They clicked a button on the Inventory GUI
if (button == 1) {
// They pressed SELECT, so switch to the Get cursor
SetCursorMode (MODE_USE);
// But, override the appearance to look like the arrow
SetMouseCursor (6);
}
if (button == 2) {
// They pressed LOOK, so switch to that mode
SetActiveInventory(-1);
SetCursorMode(MODE_LOOK);
}
if (button == 3) {
// They pressed the OK button, close the GUI
GUIOff (INVENTORY);
SetDefaultCursor();
}
if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
// scroll down
game.top_inv_item = game.top_inv_item + game.items_per_line;
}
if ((button == 5) && (game.top_inv_item > 0)){
// scroll up
game.top_inv_item = game.top_inv_item - game.items_per_line;
}
I've been meaning to ask - why do you want / need the extra button? Depending on what you want to acheive, there might be an easier way to go about it.
Don't worry, we'll get there eventually!
Is there a way to make the hand do the "talk to" interaction? That way when the new hand cursor is clicked on an inventory item it will run whatever you told it to do when "talk to" is clicked. This would be a lot simpler.
The background of the inv gui is the same, gray. But the actual background of the window where the inventory items are shows is not gray as well instead of black as it is in the default.
The size of the inventory sprites has not changed and it looked fine in the default gui. Now, some sprites are overlapping some other one and it's just a bad mess. I haven't changed anything except for adding that button.
And all the buttons are set to run script when left clicked except for the hand icon which is set to cursor mode.
I need the hand icon because there are many things that require this interaction. For instance, opening items, feeling items, etc.
Thanks for your patience. I'm so confused!
Jonathan
1. Yes, there's a way to do that, but it's not actually that much simpler. Change the Hand buttons 'New mode number' from '8' to '3'. Now, put the commands you want to run in the Items 'Talk to inventory item' interaction.
EDIT: And it's a little more difficult if you don't want the cursor to be the default 'Talk to' one.
2. I can't think of a simple way to fix this, other than importing a background for the GUI with the black box drawn on it.
3. Sounds like it is a problem with the InvDimentions, as I said. When you say "The size of the inventory sprites has not changed", what haven't they changed from? What size are the sprites you're using?
4. I have no idea why the GUI isn't working, sorry.
I'm going to try the game.sierra_inv_color command in the script to see if that changes the background color.
When I say the size of the items hasn't changed I mean the size hasn't changed from when I used the default gui inv and the spacing was fine. I say this to show that I just need to find out how to make the new gui the same as the default gui in that regard. Can you explain more about the inv dimensions and how I can change it to the default 40x22 you mentioned.
Thanks
Unless you've changed it, it is set to 40x22, and that seems to be what's casuing the problems (items overlapping, for example). I think the in-built inventory handles spacing differently to the GUI you're now using. So, I ask again, what size are your item sprites, and also what resolution are you using?
I think game.sierra_inv_color only affects the in-built inventory, but it's worth a shot.
I tried both the inv color command and the set dimensions command in both the global script (in game_start) and in the gui script and neither made a difference. Is there somewhere else this is supposed to go?
Is there any way you could upload your game somwhere for us to have a look at? As you've probably noticed, it can sometimes be difficult to give, and get, accurate advice about something you don't have in front of you.
Don't worry, though, you'll get it eventually.
I guess I could zip it and email it to you. What's your email address? That would be great!
Jonathan
WhoIsMonkey@yahoo.com
I'm busy this afternoon, but hopefully I'll be able to get to it at some point this evening, if you want.
I'm trying to email it but it's 55 meg, will your email take that large of an attachment? It's zipped and everything. Is there another way to send it?
After importing the default guis and basically starting over on the guis I got the buttons to now work on the inv.Ã, However, the cursor goes to the "talk to" cursor when clicked on the hand.Ã, I know it's using the "talk to" command, but I need the cursor to still look like hand.Ã, This is pretty easy to do I'm sure I just don't know where to do it.
I'm still trying to figure out how to change the background to black and trying to get the inv items spacing right.
Edit - I had to change the spacing to get it right. 40x22 is NOT the default even though it says it is in the help contents. Basically the only thing (besides changing the cursor) that remains a problem is the color of the inventory window. It looks dumb being the same color as the rest. I've tried the game.sierra_inv_color = 0; and it makes no difference. I'm not sure what the problem is.
To make it use the hand cursor, you need to set the button to run script, and add this to the Inventory section of the interface_click script:
if (button == 6) {
SetCursorMode (MODE_TALK);
SetMouseCursor (2);
}
As I said, I think game.sierra_inv_color only affects the default GUI, not the one you're using. However, if I'm wrong, colour 0 is transparent, not black. Try game.sierra_inv_color = 16; instead, or import a background image for the GUI.
Glad you're got it mostly working now, though I'm interested - what did you have as the default inventory size, if not 40x22?
Yay!Ã, It worked.Ã, Hooray for you.
There's got to be SOME way to change that background color, though!
Edit - nm, I just made a background image for it. It was a pain, but at least I got it done! BTW, I have no idea what the actual default is, but it was a lot wider than "22".
Jonathan Grant