Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: adevin on Wed 02/11/2005 03:39:45

Title: I need help with single cursor interface
Post by: adevin on Wed 02/11/2005 03:39:45
Hello,
I have some ideas for a game I'm working on and I'm having alot of trouble. I'm unable to do any scripting at this point, so if it's possible I'd like to keep it as simple as possible.
What I would like to do is to get rid of the icon bar GUI completely, and have only one mouse cursor that the player can use in my game. Right clicking will open the inventory, and left clicking will cause the main character to interact with whatever is clicked on. I can't figure out how to do this, and I would really appreciate some help. Sorry if my explanation of what I'm after was confusing, I'll try to elaborate if there's confusion.
Thanks
Title: Re: I need help with cursors
Post by: SSH on Wed 02/11/2005 11:44:42
Well, you'll have to do a little dabbling in scripting to do that. Or, alternately, use a template from a game that has an interface like the one you want. I'm afarid I don't knwo which template will be like this.


If you're going to go into scripting,  you'll need to modify on_mouse_click function.
Title: Re: I need help with cursors
Post by: Ashen on Wed 02/11/2005 11:54:43
Try  Rui's page (http://www.freewebs.com/skimbleshanks/templatesandmodules.htm) for templates. I think the Verb Coin, Broken Sword and ALARCOST ones are nearest to what you want.

However, as SSH said, you're going to need to do a bit of tinkering with the script, whatever you do. (If only to update the code to a newer AGS version.)
Title: Re: I need help with single cursor interface
Post by: Elliott Hird on Wed 02/11/2005 12:53:25
Go to the gui section, select iconbar and change the thing from Normal to Popup Modal. Then go into the global script, add at the very top a line saying string buffer; scroll down to on_mouse_click, put and replace everything between the { and } with this:if (button == eMouseLeft) {
  GetLocationName(mouse.x, mouse.y, buffer);
  if (buffer == "") ProcessClick(mouse.x, mouse.y, eModeWalkto);
  else ProcessClick(mouse.x, mouse.y eModeInteract);
}
else {
  show_inventory_window();
}
make all interactions with the Interact cursor. Done!
Title: Re: I need help with single cursor interface
Post by: adevin on Thu 03/11/2005 00:36:59
I appreciate the replies. I tried making the changes that Elliott suggested to the script, and I received an error message after trying to save my game:

Error (Line 45): undefined symbol 'eMouseLeft'

What am I doing wrong? Thanks again for the help.
Title: Re: I need help with single cursor interface
Post by: Gilbert on Thu 03/11/2005 00:58:27
Which version of AGS are you using? The codes Elliott posted requires V2.71 (which  isn't a good idea as it's not officially released yet).
Title: Re: I need help with single cursor interface
Post by: Elliott Hird on Thu 03/11/2005 09:11:33
eMouseLeft is just standard. wait, lemme check

2.7 code:if (button == eMouseLeft) {
  GetLocationName(mouse.x, mouse.y, buffer);
  if (StrComp(buffer, "") == 0) ProcessClick(mouse.x, mouse.y, eModeWalkto);
  else ProcessClick(mouse.x, mouse.y eModeInteract);
}
else {
  show_inventory_window();
}


2.62 code (time to upgrade!):if (button == LEFT) {
  GetLocationName(mouse.x, mouse.y, buffer);
  if (buffer == "") ProcessClick(mouse.x, mouse.y, MODE_WALK);
  else ProcessClick(mouse.x, mouse.y MODE_USE);
}
else {
  show_inventory_window();
}
You might have to change MODE_USE to MODE_INTERACT, I can't remember.
Title: Re: I need help with single cursor interface
Post by: Gilbert on Thu 03/11/2005 09:36:09
Your's was not V2.62 code, as there's if (buffer=="")

That's why I said your original codes were for V2.71, not V2.7.
Title: Re: I need help with single cursor interface
Post by: Elliott Hird on Thu 03/11/2005 09:53:42
Ups, in the 2.62 code replace buffer == "" to StrComp(buffer, "") == 0
Title: Re: I need help with single cursor interface
Post by: adevin on Thu 03/11/2005 19:55:34
I am using 2.6, and I have made all the changes that you said to with this version, but now there is another problem:

Error (line 50): Parse error in expr near 'mouse'


Line 50 looks like this:
else ProcessClick(mouse.x, mouse.y MODE_USE);
Title: Re: I need help with single cursor interface
Post by: Ashen on Thu 03/11/2005 20:14:09
There's a missing comma after mouse.y:

else ProcessClick(mouse.x, mouse.y, MODE_USE);

It might be worth your time reading through the manual (which you should've done already), to familiarise yourself with the commands, and how to use them.

And, of course, if you haven't made a major start you're probably better switching to 2.7+ now rather than later.
Title: Re: I need help with single cursor interface
Post by: Elliott Hird on Thu 03/11/2005 20:33:51
Downloading the beta would be good too, although it IS experamental and possible unstable.
Title: Re: I need help with single cursor interface
Post by: FlyRider on Fri 04/11/2005 12:31:12
I have a question. What if you want a pop-up menu whith "talk to, use, look at" etc to appear when clicking on something? And depending on what choice you make there, the player talks to, interacts with or looks at the thing.

What additional code is required for that?
Title: Re: I need help with single cursor interface
Post by: Ashen on Fri 04/11/2005 13:29:35
Do a search for Verb Coin interfaces, or use the template on Rui's site.
Title: Re: I need help with single cursor interface
Post by: adevin on Sun 11/12/2005 23:12:43
Sorry to bother you all with this again, but I've just gotten to the point where I'm adding an inventory item that the player will be using on the main character. But there's a problem: when I try to use the item on the character, it just displays the message that I assigned to his "Interact" mode. I realize this is because I did that scripting to make all left clicks "interact". How can I change the scripting to get around this problem?

I will try to explain my problem more if I'm not clear enough.
Title: Re: I need help with single cursor interface
Post by: Ashen on Sun 11/12/2005 23:20:38
You need to add a check in on_mouse_click to see if there's an active inventory item to use. Something like (assuming you're still using 2.62, and the same basic code as above):
if (button == LEFT) {
  GetLocationName(mouse.x, mouse.y, buffer);
  if (StrComp("", buffer) == 0) ProcessClick(mouse.x, mouse.y, MODE_WALK);
  else if (player.activeinv != 0) ProcessClick(mouse.x, mouse.y, MODE_USEINV);
  else ProcessClick(mouse.x, mouse.y, MODE_USE);
}


(If you're not using either of those any more, you'll need to be more specific about what you are using.)
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 17:32:10
Yes, I'm still using 2.6

I put this in the script, and now I got the inventory item interactions to work, but the character won't respond to his usual left click interactions that don't involve inventory items. Is there something else I need to add to the script?
Title: Re: I need help with single cursor interface
Post by: Elliott Hird on Mon 19/12/2005 17:35:21
I have no idea why it isn't working - are you clearing the inventory item after interaction?
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 17:38:09
Yes I am. The interactions don't work even at the start of the game when inventory interactions haven't been used.
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 19/12/2005 17:49:24
I don't know why this isn't working either ...

Is the character responding to any clicks (can you get him to react to inventory items)?
Do other characters/object run their interactions normally? (inventory & non-inventory)
Have you changed player characters - 2.6 doesn't update the player pointer.

(There was also a comma missing from the code I gave - the same mistake frome a few posts up  :-[ as I copied the code without checking it - but since that'd cause a crash, I'll assume you noticed & fixed it yourself.)
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 18:04:17
Yes, I noticed the missing comma and fixed it. Using an inventory item on anything I've assigned an interaction to (main character, other characters, hotspots) will work just fine, it's just the normal "Interact hotspot" interactions that aren't working. I didn't change player characters.
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 19/12/2005 18:31:36
OK, been a while since I used 2.62, so I'm a bit rusty ....

Try changing:

else if (player.activeinv != 0) ProcessClick(mouse.x, mouse.y, MODE_USEINV);

to:
else if (player.activeinv > 0) ProcessClick(mouse.x, mouse.y, MODE_USEINV);

I think "no active inventory" is passed as -1, not 0 as I'd thought - so even with no active inv, it's not equal to 0. Needing it to be greater than 0 should solve it.
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 19:00:15
Alright, the on_mouse_click section of the script now looks like this:

function on_mouse_click(int button) {
if (button == LEFT) {
Ã,  GetLocationName(mouse.x, mouse.y, buffer);
Ã,  if (StrComp("", buffer) == 0) ProcessClick(mouse.x, mouse.y, MODE_WALK);
else if (player.activeinv > 0) ProcessClick(mouse.x, mouse.y, MODE_USEINV);
Ã,  else ProcessClick(mouse.x, mouse.y, MODE_USE);
}


I think I've followed everything you've said correctly. If not, I thought posting this might help. At this point, for some reason, a right click will not open the Inventory GUI anymore, in addition to the left clicks on hotspots not resulting in the assigned "Interact hotspot" interactions. Sorry for all this trouble, but I'm very confused.

EDIT: Ah, I was mistaken, the normal "Interact hotspot" interactions are now working as they were before, but the Inventory GUI won't open with the right click.
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 19/12/2005 19:07:19
OK, one problem down, one to go ...

Can you show the right-click part of your on_mouse_click?
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 19:11:00
There's nothing else under on_mouse_click at all, besides the stuff I posted.
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 19/12/2005 19:13:20
Well then, how was the inventory being called, when it worked?
I'd have though the easiest way would've been a if (button == RIGHT) condition in on_mouse_click - could you have accidentally deleted it or are you using some other method? (In which case - can you show that code?)
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 19:17:49
No, I think I must have deleted it. What would the code for that be?
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 19/12/2005 19:28:24

function on_mouse_click(int button) {
  if (button == LEFT) {
    GetLocationName(mouse.x, mouse.y, buffer);
    if (StrComp("", buffer) == 0) ProcessClick(mouse.x, mouse.y, MODE_WALK);
    else if (player.activeinv > 0) ProcessClick(mouse.x, mouse.y, MODE_USEINV);
    else ProcessClick(mouse.x, mouse.y, MODE_USE);
  }
  else if (button == RIGHT) { //
    show_inventory_window();
  }
}


That should do it, or GUIOn(INVENTORY); (or whatever your Inventory GUI is called) would do, if you're not worried about changing the cursor graphic (show_inventory_window() changes the Use cursor from a hand to an arrow). The default script also has a condition to stop it doing anything if the game is paused - you might want to include that.

function on_mouse_click(int button) {
  if (IsGamePaused() == 1) {
    // Game paused, do nothing
  }
  else if (button == LEFT) { // NOTE: now 'else if', not just 'if'
    //Blah blah blah
// Etc - rest of function
}
Title: Re: I need help with single cursor interface
Post by: adevin on Mon 19/12/2005 19:32:40
Great, everything's working now, thanks alot for all your help.
Title: Re: I need help with single cursor interface
Post by: adevin on Thu 22/12/2005 20:10:58
I'm having a slight problem with inventory items, and I suspect it has something to do with the way I have right and left clicks set up. When I take an item out of the inventory, and the cursor becomes the inventory image, I can't get the cursor to change back until I've used the item on the correct hotspot. This means that my normal "Interact hotspot" functions will not work, because the cursor is stuck in the use inventory mode. What can I do?
Title: Re: I need help with single cursor interface
Post by: Ashen on Mon 02/01/2006 16:48:08
Depends on how you want it to work.

You could set up unhandled_event so that if you try to use an item on a hotspot, character or object that doesn't have an interaction set up, it either clears the active item (sets no item as active), or runs the default 'Interact' interaction.You'll also have to add a command to the 'Use inventory on hotspot' interaction - if there's any inventory interaction set up, AFAIK unhandled_event won't be run, even when you use a different item.
You could also use unhandled_event to make it so clicking on nothing clears the active item.
(Both of these can be done without unhandled_event - using it just saves you from having to write the same few lines out over and over. Look it up in the manual or a forum search for more details.)

However, it might be simpler to alter the right click function slightly, so that it clears the active inventory item if there is one, and opens the inventory if there isn't, e.g.:

  else if (button == RIGHT) { //
    if (player.activeinv > 0) SetActiveInventory(-1);
    else show_inventory_window();
  }