Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 12/12/2005 14:06:52

Title: Don't walk when click on object... (SOLVED)
Post by: on Mon 12/12/2005 14:06:52
I have one object that I dont want my character to walk to when he clicks on it. It's a door. The object is turned on when my character opens the closed door ( hotspot) and then when I press walk to  "open door" I want to go to new room right away, not see the character go to the bottom-left corner of the door-object before switching room. I can't set walk to point for object either. Anyone else having this problem?! Need help now.
Title: Re: Don't walk when click on object...
Post by: Ashen on Mon 12/12/2005 16:17:29
Objects don't have walk to points, you have to script that manually. If you don't want the player to move to an object before an interaction - just don't script it.

However, there's no easy (default) way to have an interaction run when you 'Walk to' something.
AFAIK, you have to enable 'Don't automatically move character in Walk mode', and manually script it to walk most of the time (although, this might be easier than I'm thinking - I've never actually tried). This lets you use if(mouse.Mode == eModeWalkto in the 'Any click on ...' interaction.
Title: Re: Don't walk when click on object...
Post by: on Mon 12/12/2005 16:27:22
Quote from: Ashen on Mon 12/12/2005 16:17:29
Objects don't have walk to points, you have to script that manually

This is what I want to do, however all the script I have found on this forum hasn't worked. Please write down the exact script for walk-to-point for objects and I will be very very happy :-)
Title: Re: Don't walk when click on object...
Post by: Ashen on Mon 12/12/2005 17:13:36
Character.Walk command (http://www.adventuregamestudio.co.uk/manual/Character.Walk.htm)

Is all I meant ... you'll have to add player.Walk( ... ); command (probably blocking would be best) to every interaction.

If you wanted to make it more automatic, you could use Custom Properties (http://www.adventuregamestudio.co.uk/manual/Custom%20Properties.htm) to sort-of set walk-to coordinates.
If you wanted to make it even more automated, I suppose you could add a check to on_mouse_click to see if an object has been clicked on, and move the player accordingly. Something like (untested):

// on_mouse_click
  else if (button == eMouseLeft) {
    Object *theObj = Object.GetAtScreenXY(mouse.x, mouse.y);
    if (theObj != null) player.Walk(theObj.GetProperty("WalkToX"), theObj.GetProperty("WalkToY"), eBlock);
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
// Rest of on_mouse_click


But what scripts have you tried, and how/why/in what way didn't they work?
Title: Re: Don't walk when click on object...
Post by: on Mon 12/12/2005 17:46:19
He walks to the bottom left corner of the object first and then he walks to the "walk to point"
Title: Re: Don't walk when click on object...
Post by: on Mon 12/12/2005 22:35:21
Quote from: Ashen on Mon 12/12/2005 17:13:36
Character.Walk command (http://www.adventuregamestudio.co.uk/manual/Character.Walk.htm)

Is all I meant ... you'll have to add player.Walk( ... ); command (probably blocking would be best) to every interaction.

If you wanted to make it more automatic, you could use Custom Properties (http://www.adventuregamestudio.co.uk/manual/Custom%20Properties.htm) to sort-of set walk-to coordinates.
If you wanted to make it even more automated, I suppose you could add a check to on_mouse_click to see if an object has been clicked on, and move the player accordingly. Something like (untested):

// on_mouse_click
Ã,  else if (button == eMouseLeft) {
Ã,  Ã,  Object *theObj = Object.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Ã,  if (theObj != null) player.Walk(theObj.GetProperty("WalkToX"), theObj.GetProperty("WalkToY"), eBlock);
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  }
// Rest of on_mouse_click


But what scripts have you tried, and how/why/in what way didn't they work?

Whatever I try my character seem to move to the objects bottom left corner before he walks to the other coordinates... seems strange that nowone else has had this problem...
btw I didn't get you script to work. I use the FOA template. Anyone else haveing this problem?
Title: Re: Don't walk when click on object...
Post by: Ashen on Tue 13/12/2005 15:01:27
That shouldn't be happening ... and I can't see anything in the FOA template that would make it. (Although, admittedly I can't get it to work properly).

Is it possible you've left code in from a previous attempt that't making it do that? I ask agai: What have you already tried?

(Note: From a blank game, for me, that code works fine - I'd probably add a check whether the object had anything set for the current mode, but it works OK as is.)
Title: Re: Don't walk when click on object...
Post by: on Tue 13/12/2005 17:02:05
I get the error "parse error at 'else'" when I use your code in a new clean game...Btw to get Foa template to work with 2.7 I remember that I had to change the code in a few places..
Title: Re: Don't walk when click on object...
Post by: Ashen on Tue 13/12/2005 17:09:15
where exactly are you putting the code? There should already be a bit (around line 60) that says:

  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }


You just need to add the two other lines to that.

EDIT: I think I've found the bit in the FOA template you need to change...
It's around line 523, in the GoTo() function, the bit that starts If locationtype ==3) {. If you want to use the template, take those other lines I gave you out of on_mouse_click, and change the GoTo() bit to:

     else if (locationtype==3) {
       Object *theObj = Object.GetAtScreenXY(mouse.x, mouse.y);
       xtogo=theObj.GetProperty("WalkToX");
       ytogo=theObj.GetProperty("WalkToY");
     }


Provided you've set up the Properties right, that should walk to (WalkToX, WalkToY), instead of the bottom left corner of the object.
Title: Re: Don't walk when click on object...
Post by: on Tue 13/12/2005 19:08:48
I think I have another FOA temp. This is what it looks like on the "mouse click-part"

//   Handling room clicks:
//-----------------------------------------------------
  else if (button==LEFT || button==RIGHT) {
   
    if (button==RIGHT) SetMode(GetDefaultAction(mouse.x,mouse.y));// set the default mode when right click
   
    if (Extension(GSlocname)==EXITS_EXTENSION){// if its an 'exit'
        HighlightActionBar();
        WalkOffScreen();
      }
     


   
    else if (ALWAYS_GO_TO_HOTSPOTS==1 && ExtensionEx(2,GSlocname)!='d' && GetLocationType(mouse.x,mouse.y)!=0 ){
       UpdateActionBar(mrx,mry);
       HighlightActionBar();
       if (Go()==1)   ProcessAction(GetMode(),mrx,mry);
       return;
    }
    else ProcessAction(GetMode(),mrx,mry);
  }


This part is concering room clicks...
Title: Re: Don't walk when click on object...
Post by: Ashen on Tue 13/12/2005 19:20:35
Yes, sorry, ignore the on_mouse_click stuff - that was before I realised you were using a template (for future reference, it's best to mention stuff like that up front, it saves people like me from telling you things are totally irrelavant).

Like I said, I'm fairly sure the part you actually need to change is further down the script, around line 523, in a custom function called GoTo.
Title: Re: Don't walk when click on object...
Post by: on Tue 13/12/2005 21:54:00
Ok, I tried to changed that line and it worked perfect, thx man!!!  :)
I was a bit slow this time lol
Title: Re: Don't walk when click on object... (SOLVED)
Post by: Proskrito on Sat 17/12/2005 14:00:27
you could have named the object with a second 'd' extension, like 'name>ld'. this way the player wouldnt go there. The same applies to hotspots, characters, etc.
Or, if you dont want the player go to things automatically, you can set the define ALWAYS_GO_TO_HOTSPOTS to 0.
Title: Re: Don't walk when click on object... (SOLVED)
Post by: Ashen on Sun 18/12/2005 11:23:57
Thank you, I hadn't noticed that (no offence, but I found the script a little hard to decipher).
However, since m79 wanted to change the default behaviour for objects, just re-naming them all seems a little long winded. Also, ALWAYS_GO_TO_HOTSPOTS looks like it would affect everything, right (i.e. won't walk to characters or hotspots either)?

And, since you're here: How about some updated versions of your templates? ;D

EDIT: Just re-read, and I don't know if m79 did want to change the defualt behaviour, or just for one object ... Ooops.
Title: Re: Don't walk when click on object... (SOLVED)
Post by: Proskrito on Sun 18/12/2005 13:32:30
QuoteThank you, I hadn't noticed that (no offence, but I found the script a little hard to decipher)
yes, i know the code is might not be very friendly, but thats the purpose of the documentation : )
QuoteHowever, since m79 wanted to change the default behaviour for objects, just re-naming them all seems a little long winded
Sorry, i didnt read that, you are right
QuoteALWAYS_GO_TO_HOTSPOTS looks like it would affect everything, right (i.e. won't walk to characters or hotspots either)?
You are right again : )
QuoteAnd, since you're here: How about some updated versions of your templates?
Well, if i can learn the new scripting system and get some free time in christmas, i could try