Random Character Movement [SOLVED]

Started by markcullinane, Sat 29/01/2005 18:36:23

Previous topic - Next topic

markcullinane

Okay. I've got an enemy on the screen, and I want him to move about in a random patterm across the screen. I don't want to use MoveCharacterPath (because a) I'd have to specify all the movements, and b) it can only do a certain number of movements). I'm thinking about using the Random function, but I tried repeatedly executing random movements but the enemy can't move as the function keeps executing and picking a different movement that I input into the function.
Anyone know what to do?


strazer

Code: ags

function repeatedly_execute() {
  //...

  if (character[GUY].walking == 0) MoveCharacter(GUY, Random(game.room_width), Random(game.room_height));

  //...
}


Does this work for you?

markcullinane

Hi, I tried out your method strazer. I'm a beginner when it comes to the character variables, I usually stay away from them, so this may be why I'm having some problems.

I put in your code in repeatedly_execute in the room, changing obviously the character's name but keeping all the rest. It has absolutely no effect in the game though, I'm not sure why. Any other ideas?

Scorpiorus

Did you set up an appropriate Repeatedly execute interaction with a Run Script action containing strazer's code? Because just putting "function repeatedly_execute() {..." into room script won't work -- this only worls for the main global script.

Additionally, ensure the character is starting on a walkable area.

monkey0506

Well it was never specified whether this interaction was supposed to take place in just the one room, or in every room... That would make a difference.

markcullinane

Ah, right. I only want this to apply to one room- I put it in the global script, and it works fine, but only while the applicable character is in that room, so the game just crashes if I leave the room.

So I'm looking for a way for it only to apply to this particular room, or else for the global script, something like: while (character x) is in room y.....[script here]

Not sure how to do it though.

Scorpiorus

Quote from: markcullinane on Mon 31/01/2005 15:22:41So I'm looking for a way for it only to apply to this particular room, or else for the global script, something like: while (character x) is in room y.....[script here]
That's why I asked you if you set up the room Repeatedly Execute interaction.

- Open room interaction editor ( [ i ] - button )
- Choose Repeatedly execute
- Choose Run script
- Edit script and put the code in question in there:

if (character[GUY].walking == 0) MoveCharacter(GUY, Random(game.room_width), Random(game.room_height));

Thus, you set up a repeatedly execute function for a certain room.

markcullinane

Thanks a million, that solves it completely- not sure why it didn't work the first time, but it works now anyway.

Really appreciate it!

Problem solved.

SMF spam blocked by CleanTalk