Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zeta_san on Thu 20/01/2022 21:10:30

Title: [SOLVED] character not player to walk back and forth
Post by: zeta_san on Thu 20/01/2022 21:10:30
Hi everyone

I would like a character (a bird) not player to walk back and forth in a loop

I created the loop
I created the character

thank you
Title: Re: character not player to walk back and forth
Post by: Rik_Vargard on Thu 20/01/2022 21:44:46
I hope this helps you (means your bird has to be an object i think)  > https://www.adventuregamestudio.co.uk/forums/index.php?topic=50145.0
Title: Re: character not player to walk back and forth
Post by: zeta_san on Thu 20/01/2022 21:52:08
thanks i will try it
Title: Re: character not player to walk back and forth
Post by: Pax Animo on Thu 20/01/2022 22:24:14
Quote from: Rik_Vargard on Thu 20/01/2022 21:44:46
I hope this helps you (means your bird has to be an object i think)  > https://www.adventuregamestudio.co.uk/forums/index.php?topic=50145.0

From my understanding, it doesn't have to be an object, you'll be most likely better off using a character as characters act in many ways like objects but without certain restrictions.
Title: Re: character not player to walk back and forth
Post by: eri0o on Thu 20/01/2022 22:29:34
if it's a character you can just pass WalkWhere property to be eAnywhere when the character is walking, to ignore walkable areas.

An example can be like this, adding this code in your room script - this makes the bird walk randomly though, not sure exactly what you want, if the character has a route, check in which point of the route it is, then make it walk to the point it makes sense (if it's at point A, walk to B, if it's in point B, walk to A, if it's in neither, don't tell nothing)

Code (ags) Select
void repeatedly_execute_always()
{
  if(!cBird.Moving) {
    cBird.Walk(Random(Room.Width) /* full room */,
               Random(50) /* only top to 50 px */,
               eNoBlock /* can't block on rep exec always*/,
               eAnywhere);
  }
}
Title: Re: character not player to walk back and forth
Post by: zeta_san on Fri 21/01/2022 09:58:49
Thanks everyone you are fantastic! this forum doesn't make me feel alone ..

I modified it like this.

Code (ags) Select
function room_RepExec()
{
if(!cMerlo.Moving) {
    cMerlo.Walk(Random(Room.Width) /* full room */,
               Random(50) /* only top to 50 px */,
               eNoBlock /* can't block on rep exec always*/,
               eAnywhere);
}}


for a path from 50 to 150 and 150 to 50, should it be removed randomly?

AddWaypoint?

if(!cMerlo.Moving) { 
cMerlo.Walk(16, 123);
cMerlo.AddWaypoint(1, 123);
Title: Re: character not player to walk back and forth
Post by: zeta_san on Fri 21/01/2022 11:24:10
function room_RepExec()
{
if(!cMerlo.Moving)

{
cMerlo.AddWaypoint(36, 129);
cMerlo.AddWaypoint(18, 129);
}}

:grin:

Thanks
Title: Re: [SOLVED] character not player to walk back and forth
Post by: Cassiebsg on Fri 21/01/2022 20:09:07
Please not that when you place the code in RepExec instead for repeatedly_execute_always(), your bird will stop whenever there's a blocking action going on, like your character walking in a block mode or talking... so, if you wish your bird to not freeze mid flight while your player character is chatting or doing something in blocking mode, I suggest you use repeatedly_execute_always().  ;)
Title: Re: [SOLVED] character not player to walk back and forth
Post by: newwaveburritos on Sun 23/01/2022 05:17:54
It also might be worth mentioning that it's probably worthwhile to keep your code formatted so it's easy to read.  You might have done this that way just for the forum post but the more cod you get together the harder it will be to read.  Keeping the curly braces separate will help you distinguish where the if statement ends and where it is in the function especially if you have more than one.  Just a thought.  Good luck with the project!