Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calavera on Thu 17/02/2011 21:32:28

Title: [AGS problem] Walk function
Post by: Calavera on Thu 17/02/2011 21:32:28
Hi, when i play and i click in a point like a crazy the main character hangs.
I think the problem is in the function Walk indeed when i run the command cEgo.Walk in the repeatedly execute function  my character freezes.

Can anyone help me?
Title: Re: [AGS problem] Walk function
Post by: Calin Leafshade on Thu 17/02/2011 21:34:55
why *would* you click like crazy in a single point?
Title: Re: [AGS problem] Walk function
Post by: Calavera on Thu 17/02/2011 21:44:33
because i think many player can do
Title: Re: [AGS problem] Walk function
Post by: Giowe on Thu 17/02/2011 21:48:03
right. i have the same problem. anyone can solve this?
Title: Re: [AGS problem] Walk function
Post by: Snarky on Thu 17/02/2011 21:53:48
The issue is that every time you click, the game recalculates the path for the character to walk to that spot. And the pathfinding in AGS is fairly slow, so this causes the game to hang for a moment. Apart from optimizing the A* implementation used by AGS (someone once claimed they could do it faster in an in-game script than the built-in implementation), you'd have to stick in some logic to keep multiple clicks in the same spot from doing the recalculation each time.
Title: Re: [AGS problem] Walk function
Post by: Khris on Thu 17/02/2011 21:58:50
Hi, when I'm working on my PC and I pour a bucket of water into the case like a crazy the PC stops working.
I think the problem is in the bucket of water indeed when I pour water over other electric appliances they stop working, too.

Can anyone help me?
Title: Re: [AGS problem] Walk function
Post by: Giowe on Thu 17/02/2011 22:02:26
Quote from: Khris on Thu 17/02/2011 21:58:50
Hi, when I'm working on my PC and I pour a bucket of water into the case like a crazy the PC stops working.
I think the problem is in the bucket of water indeed when I pour water over other electric appliances they stop working, too.

Can anyone help me?

just try to do the same in monkey island. it goes right. that was well designed. this is NOT well programmed and i want for my game the best solution possible. if in your opinion this is not important don't waste your time posting stupid things. tnx.
Title: Re: [AGS problem] Walk function
Post by: Calavera on Thu 17/02/2011 22:03:16
So there aren't any other solution? I have to implement another computational method for the A* algorithm and overload the Walk method?
Title: Re: [AGS problem] Walk function
Post by: Calin Leafshade on Thu 17/02/2011 22:07:25
So, you guys are repeatedly clicking in the same location over and over again?

If you really think that players will do that you could just add a timer to the click and not allow clicks within a second of each other and if the click is very close to the previous click.

But really it seems like you are inventing a problem that doesnt really exist.
Title: Re: [AGS problem] Walk function
Post by: Khris on Thu 17/02/2011 22:12:25
This should work:

int timeout = 10;

int timer;

void repeatedly_execute_always() {
  timer++;
  if (timer >= 10000) timer = 1;  // avoid overflow
}

int ox, oy;

void on_mouse_click(MouseButton button) {
  if (timer < timeout && mouse.x == ox && mouse.y == oy) ClaimEvent();
  else {
    timer = 0;
    ox = mouse.x;
    oy = mouse.y;
  }
}


Stick this in a script above the Global one (or incorporate it into Global.asc).

What it does is simply ignore any click at the same location as the previous one within timeout frames.

Btw, I recognize this is something people take seriously and I apologize for making fun of it. However, I personally wouldn't implement stuff that helps people with a serious personality disorder to play my game.
Title: Re: [AGS problem] Walk function
Post by: hedgefield on Thu 17/02/2011 22:34:55
Quote from: Khris on Thu 17/02/2011 21:58:50
Hi, when I'm working on my PC and I pour a bucket of water into the case like a crazy the PC stops working.
I think the problem is in the bucket of water indeed when I pour water over other electric appliances they stop working, too.

Can anyone help me?

If this was Facebook I would have Like'd that post.

The situation you describe seems like a very OCD thing to do, I don't think you have to be afraid many people will act this way. The only time I ever did something similar was to find that óne pixel in the wheel puzzle room in Broken Sword 2 that lets you skip that whole section.
But if you're really serious about it the suggestions above should go a long way to help you with this 'problem'.
Title: Re: [AGS problem] Walk function
Post by: Calavera on Thu 17/02/2011 22:58:16
The problem there also when i click in a different position, i would fix this because in my game there are many scene with a long backgorund and the player is forced to click at the screen side repeatedly. 
Title: Re: [AGS problem] Walk function
Post by: Calin Leafshade on Thu 17/02/2011 23:03:05
Khris' function should probably be altered to catch mouse coords related to the *room* instead of the screen to account from scrolling rooms.

And while the pathfinding isnt perfect this is easy to script around. It's not a priority fix.
Title: Re: [AGS problem] Walk function
Post by: Snarky on Fri 18/02/2011 08:57:42
I always do this when I need a character to walk across a scrolling room. Keep the cursor in one position and keep clicking while the room scrolls. The fact that it causes the game to stutter has long been one of my minor annoyances with AGS.
Title: Re: [AGS problem] Walk function
Post by: Yeppoh on Fri 18/02/2011 10:51:11
It depends from the gameplay you wish, but I got around this by scripting a double click to do either:
- a jump;
- a teleport;
- running;
- any secondary action;
You choose.

For the scrolling room, I like how the Broken Sword team dealed with that, by using a special interaction to that effect when the mouse is on the scrolling part of the screen. Or you can make it Zack and Wiki style, keeping the mouse button down to control the character walk.