Version 3 "Function Object_AnyClick" Help.

Started by alisa_tana, Tue 29/01/2008 19:20:32

Previous topic - Next topic

alisa_tana

I know I'm missing something.

I just upgraded to the new v3.0, and I'm having trouble setting up the interactions for an object. 

I created the object, named it oCHAang, clicked on Events, and then clicked on the Any Click, which takes me to the room script, like it should.

So I put in something simple, for example:
Code: ags
function oChAang_AnyClick(){
Display("Hello");
}


And then test it out.  and when I click on that object, nothing happens.

I've tried it with the different events too, and all of them seem to behave the same.

The only other thing I've got in the room script right now is:
Code: ags
function room_AfterFadeIn(){
SetCursorMode(eModeInteract);
}
to change the cursor.

Please help this poor ignorant fool figure out what she's missing.


mchammer

This is from old thread, havent tested it tho so im not sure if it works:
Quote
Yeah, by default AGS won't run anyclick interaction while in walk mode. To change that behavior open the general settings pane and put a tick next to the "Don't automatically move character in walk mode" option. But with that option enabled that player won't be able to move around, therefore to correct it you have to adjust the on_mouse_click function in the global script by putting an explicit code that handles moving:

function on_mouse_click(int button) {
   // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button==LEFT) {
      if (GetCursorMode() == MODE_WALK) MoveCharacter(GetPlayerCharacter(), GetViewportX()+mouse.x, GetViewportY()+mouse.y);
      ProcessClick(mouse.x, mouse.y, GetCursorMode());
   }
   else {   // right-click, so cycle cursor
      SetNextCursorMode();
  }
}

Code there is bit old, I guess new code would be something like that:
Code: ags

function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
  else if (button == eMouseLeft) 
    {
    if (mouse.Mode = eModeWalkTo) player.Walk(GetViewportX()+mouse.x, GetViewportY()+mouse.y,eNoBlock, eWalkableAreas);
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }
  else // right-click
    {
    mouse.SelectNextMode();   
    }
  }
My 40 bullets - An action/war game.

alisa_tana

Ah thanks!

I don't really need the Walkto mode anyway, but just turning that option off wasn't enough.

Putting in that script worked after correcting the (mouse.Mode == eModeWalkto)  ;p

Khris

First of all, when I tested it, any click worked flawlessly, as expected.
Secondly, "SetCursorMode" isn't supported. It's old code from 2.62 and previous versions, could still be used up until 2.72 but is definitely not supported in 3.0.
The proper code should be "mouse.Mode = eModeInteract;"

It might have to do with capitalization: your object is called "oCHAang" with a capital H.
In the script you've posted, however, the function is called "oChAang_AnyClick", with a lowercase h.
As long as there still is a function called "oCHAang_AnyClick" somewhere in the room script, AGS won't throw an error. But in this case, "oChAang_AnyClick" is never called, thus the Display command is never run.

mchammer: the stuff you posted address something else. (AnyClick isn't called after walkto clicks)

mchammer

Quote from: KhrisMUC on Wed 30/01/2008 17:49:21
mchammer: the stuff you posted address something else. (AnyClick isn't called after walkto clicks)

I didnt test it, it's just a quote from old thread and tells how to get AnyClick called after walk to click.


My 40 bullets - An action/war game.

monkey0506

#5
Quote from: KhrisMUC on Wed 30/01/2008 17:49:21It's old code from 2.62 and previous versions, could still be used up until 2.72 but is definitely not supported in 3.0.

What? You're saying that turning "Enforce object-based scripting" off doesn't work in AGS 3.0? Chris should know about this!

Quote from: KhrisMUC on Wed 30/01/2008 17:49:21It might have to do with capitalization: your object is called "oCHAang" with a capital H.
In the script you've posted, however, the function is called "oChAang_AnyClick", with a lowercase h.

Actually this is completely irrelevant. She could have the function named "Doobywhapdotorg_AnyClick" and AGS couldn't care less. So long as the function is properly linked in the Events pane it would be called.

The solution provided isn't necessarily the most elegant one, but if you had read alisa's response, you would see that she got it working. Presumably selecting "Don't automatically move character in walk mode" means that the any-click function will in fact be run in place of the Character.Walk command. This is why the code provided manually calls Character.Walk for eModeWalkto, and continues to allow all other clicks to be processed normally. If this option is enabled, it would move the character and run the any-click interaction; otherwise, it would process the walk command twice. So you wouldn't want to do this if you are using the eModeWalkto mode (i.e., you have "Don't automatically move..." unchecked), but otherwise it should be fine.

Edit: Didn't mean to imply you hadn't been reading there Khris, it just seemed to me that you had missed the "that script worked" bit. := Oh, and also note that I was being mostly facetious about the OO-scripting. ;D I figured you probably just assumed-the-option-was-removed/couldn't-find-it/wanted-it-gone-so-presumed-it-was.

Khris

Ah yes, my bad. Somehow I was convinced that 3.0 had finally gotten rid of the old-style code stuff.

I'm very aware that it's sufficient if the function is properly linked, regardless of the object's name. I assumed that somehow the function's name got accidentally erased, then retyped from memory or something like that.

And finally, I felt that the posted workaround was awkward and superfluous.
That's why I posted although the OP had stated she got it working (which I was very aware of, too).

And thanks for the technical lesson :=

SMF spam blocked by CleanTalk