How can I call button click functions? and more..

Started by , Tue 11/07/2006 23:13:52

Previous topic - Next topic

mordy

Hey guys! I've been using the forum's search feature and got a lot of good, helpful information, but I haven't found any relevant solution to the following problems.

I created my own LucasArts style gui, with the action verbs, inventory scroll arrows and boxes at the bottom, as well as the status bar.

1) How can I call button click functions? I enabled the mousewheel to be able to scroll Up and Down the inventory arrows. Instead of simply calling myinventory.ScrollUp(), for example, I would like to call the actual button click function: invArrowUp_Click(). I also need this for keypresses, such as calling the VerbLook_Click() function when I press the "L" key on the keyboard.


Other less important issues:


2) Whenever I perform an action, such as performing a Pick Up on an object,Ã,  Use on something, or the character talks, the game pauses and the LucasArts style GUI windows I created at the bottom become grey. I would like for the GUI to not change to the grey color. I would also like to be able to click out of an action. For example, if I go to Pick Up an object, I would like to be able to click somewhere on the screen to cancel that action if it hasn't occurred yet.

3) Revert to Walk mode after any action is performed? This only half works.. Here's what happens: If, for example, I click Pick Up then click an object, the Pick up mode remains active. If, however, I move the mouse cursor away from the object after I click on it using Pick up (and the character is still walking over to the object), it reverts to walk mode when the object gets picked up (which is what I want). Hence, it only half works :p

4) Walk to an object in "Walk to" mode? I know it's possible with Hotspots..

5) Use an inventory item on itself or on another item to produce a default unhandled event? Nothing happens when I do that. The status bar simply changes to "Use inv1 on inv2".


I hope all that was clear. Sorry for asking too much! The first question is the most important one, the rest are minor.. Thanks a lot!

Ashen

1) Exactly the same way you call any other function - just type it into the script. You'll need to look at the function declaration to see what parameters it needs (buttons, for example, need a GUI Control and a MouseButton parameter). What the parameters are doesn't really matter (unless you've coded it that it does), so just pass the buttons name an eMouseLeft, e.g.:
Code: ags

invArrowUp_Click(invUpArrow, eMouseLeft);


This has been mentioned before (sort of), but it's not the easiest thing to search for.

Remember that functions can only be called after they've been declared, so you'll need to move all the button click functions to the top of the global script. (The other, possibly easier, way to do this would be to make a function at the top containing all the code, and call that from on_key_press and the Button function.)

2)
Again, this has been asked before.

3) How are you doing the half working? Show us your code and we might be able to help, as it might be easier to fix what you've got than have to explain from scratch.

4) It's slightly more involved with Objects. You have to select the 'Don't automatically move character in Walk mode' option, and edit the on_mouse_click function to do Character.Walk if 'Walk to' mode is used. You might also want to make it so it only moves if you click on nothing, allowing you to have some other action when clicking on an Object/Character.

5) Have you looked up unhandled_event (bottom of this page)? If so, what've you trying that isn't working? (Post code if needed.)
I know what you're thinking ... Don't think that.

Khris

I'm not sure if this is what you wanted to know, but I'll post it anyway:

4) Are you referring to the fact that you can enter walk to-coordinates for hotspots but not for objects?
Create two custom properties (select an object, click "Properties...", then create one named "ox" and a second one named "oy" or something like that, type is obviously a number, default should be -1 for both, enter any description you want).
Then enter the walk to-coords for every object.

The values can now be accessed in the script e.g. like this:
Code: ags
// on_mouse_click
Object*ob=Object.GetAtScreen(mouse.x, mouse.y);
if (ob!=null) {
Ã,  int x=ob.GetProperty("ox");
Ã,  int y=ob.GetProperty("oy");
}
...
if (x!=-1) {
Ã,  player.Walk(x, y, eBlock);
}
...

mordy

1) Ok I get how to pass the parameters to the functions, I was a bit confused on what to pass for the GUIControl. Still, the arrow keys don't "light up", as in, they don't flash their respective "pushed image" sprites, like they would when I mouse-click on them. Not a big deal really..

2) haha, that option was right there in the general settings.. how silly. I was hoping there'd be a way to click out of an event. So for example, if I tried to Pick Up an item, is there a way to click anywhere on the screen to cancel / break out of the script? Again, really minor..

3) In the on_mouse_click event, I have mouse.Mode = eModeWalkTo under the ProcessClick. For the right click, it checks if I click on "nothing" (no object, hotspot, or character) then reverts to eModeWalkTo. The last line of every Pick Up Object script is mouse.Mode = eModeWalkTo. So I have that in 3 different places as you can see. That's how it's half working I guess. Note that the last line I mentioned only works if I move the mouse cursor AWAY from the object AFTER I click on it with the Pick Up interaction mode. So, while the character is moving to the object to go pick it up, I move the mouse cursor away from the object so that it reverts to Walk mode when the character finishes picking up the object. Sorry if that sounded confusing..

4) Solved. I did what you said about disabling auto-walk, Ashen. Thanks KhrisMUC, but unfortunately that moves the character to the object's real coordinates which isn't what I want. It doesn't work well with depth if you know what I mean.

5) I'm using tons of unhandled events already. For some reason the "Use inv on inv" unhandled isn't working right. First of all, here's a little piece of code I have for the Use Inventory mode that changes the status bar:

...
else if (mouse.Mode == eModeUseinv)
{            
Ã,  Ã,  if ((player.ActiveInventory != null) && (verb == "Use "))
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  mouse.Mode = eModeUseinv;
Ã,  Ã,  Ã,  Ã,  player.ActiveInventory.GetName(invItem);
Ã,  Ã,  Ã,  Ã,  StrCat(verb, invItem);
Ã,  Ã,  Ã,  Ã,  StrCat(verb, " with ");
Ã,  Ã,  }
}

And here's an example part of what I have in the unhandled events:

if (what==5)
...
else if ((type == 3) && (LastButton != VerbUse))
Ã,  Ã,  player.Say("Nothing happens.");

So from the code after the " && " you can see why it doesn't work when I try to Use inv on inv. I made it that way because if I click on Use, then click on an inventory item, the unhandled event for it goes off, which is really annoying because I still haven't finished what I was trying to do. I want the unhandled event to happen AFTER I tried a combination of items, or an item used on itself. Know what I mean?

Thanks a lot for your help, most of the other questions got solved for the most part!


SMF spam blocked by CleanTalk