NPC's AI's problem- (Random Movement)

Started by Baily63, Mon 19/03/2007 01:58:51

Previous topic - Next topic

Baily63

     Hi, me AGAIN! ;D I suck at things I have to figure out for myself. Look, I want it so my character (NPC, a.k.a, SQUIRREL) SQUIRREL will walk around the room with-out me having to click on him or andything. He just does it without me having to move the mouse. Is there a way to make SQUIRREL do that without scripting? If there is, tell me. If I have to script, please tell me the script and where to enter it. Please help!  :'(

P.S Oh yeah anyone know any good GUI tutorials?  ???

Creator

You could try this:

Code: ags

if (cSquirrel.Room == player.Room) {
     if (cSquirrel.Moving == false) {
     cSquirrel.WalkStraight(Random(320), Random(200), eNoBlock);
}
}


and put it in repeatedly_execute
Hope it works well  ;)

Ashen

Quote
I suck at things I have to figure out for myself.
This isn't a very good reason for posting. You should at least TRY to work things out yourself before coming here. If you have - tell us what you tried, and it'll help us narrow down your probelms, or get a clearer idea what exactly you want.

Please, use more descriptive titles in the future. It'll help people find the same answer in the future. (Case in point - I know this question has been asked at least a dozen times, but searching only turned up two, and they were old-style coding.)

Creator's code should work perfectly, but I'd make these changes:
Code: ags

if (cSquirrel.Room == player.Room) {
   if (cSquirrel.Moving == false) {
     cSquirrel.WalkStraight(Random(Room.Width), Random(Room.Height));
  }
}


Using Room.Width/Height maks it compatable with scrolling rooms (larger than 320x200). eNoBlock is the default for Character.WalkStraight, so you don't need to add the parameter (it doesn't matter if it's there, it just doesn't need to be).

QuoteP.S Oh yeah anyone know any good GUI tutorials?  ???
What sort of GUI tutorials? As in, what do you want to make a GUI for?
If you're interested in somethin specific (e.g. Save/Load GUIs), a forum search will probably turn something up.
However, GUIs require scripting - not necessarily complex scripting, but you CAN'T use Interaction Editor commands for them, so there WILL be some script involved. You might be better gaining more general confidence and ability, before you get into GUIs.
I know what you're thinking ... Don't think that.

Baily63

Doesn't work. Says un-expected "if" when i try testing. I did copy and paste in the rapidly-repeate section though...

Ashen

'unexpected if' errors usually mean it's outside of a function, so you've probably just misplaced a brace somewhere. Try using Ctrl-B to match the braces ({ and }), or post your repeatedly_execute section if you can't find anything. (If there's a problem in the script, it helps if you show the script ;))
I know what you're thinking ... Don't think that.

Baily63

KK here's my rapidly exucute section, can u copy and paste it into your forum and then in bold make the changes needed?

// main global script file

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
  {
  }
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

  // put anything you want to happen every game cycle here

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) // called when a key is pressed. keycode holds the key's ASCII code
  {
  if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
  if (keycode==17) QuitGame(1); // Ctrl-Q
  if (keycode==363) SaveGameDialog(); // F5
  if (keycode==365) RestoreGameDialog(); // F7
  if (keycode==367) RestartGame(); // F9
  if (keycode==434) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode==9) InventoryScreen(); // Tab, show inventory
  if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode==22) Debug(1,0); // Ctrl-V, version
  if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
  }
#sectionend on_key_press  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
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)
    {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }
  else // right-click, so cycle cursor
    {   
    mouse.SelectNextMode();
    }
  }
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button)
  {
  }
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE



#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
 
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

Ashen

OK, that's weird, I don't see any ifs out of place. Did it give you a line number?
I also don't see the cSquirrel code - where'd it go?

Why do you have three #sectionstart/end bits for rep_ex? Fortunately only one actually has the function in, so I don't think it's a problem, it just looks wrong. Have you been cuttng and pasting a lot, or something?
I know what you're thinking ... Don't think that.

Baily63

#7
well, i took the code I put in out

can you copy and paste my script into a forum post, and then make the changes?

Does any1 know the script I should post and where (more spacificly), because nomatter what script i put in my games, it always comes up with an error message. Can someone just solve my question about how to make my squirrel randomly run around?

Khris

Code: ags
// main global script file

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
  {
  }
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() // put anything you want to happen every game cycle here
{
  if (cSquirrel.Room == player.Room && cSquirrel.Moving == false)
    cSquirrel.WalkStraight(Random(Room.Width), Random(Room.Height));
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) // called when a key is pressed. keycode holds the key's ASCII code
  {
  if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
  if (keycode==17) QuitGame(1); // Ctrl-Q
  if (keycode==363) SaveGameDialog(); // F5
  if (keycode==365) RestoreGameDialog(); // F7
  if (keycode==367) RestartGame(); // F9
  if (keycode==434) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode==9) InventoryScreen(); // Tab, show inventory
  if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode==22) Debug(1,0); // Ctrl-V, version
  if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
  }
#sectionend on_key_press  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
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) 
    {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }
  else // right-click, so cycle cursor
    {   
    mouse.SelectNextMode();
    }
  }
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) 
  {
  }
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE


Don't double-post, let alone triple-post. It's obvious that you didn't read the rules of this forum, so it might be a good idea to do that now.

And remember, on the main page it says:
QuoteAGS is not for everyone. To make more advanced parts of a game, such as cutscenes, you will need to be prepared to learn the scripting language. It is recommended that you have at least a basic knowledge of computers before attempting to use AGS - such as, you know what a PCX file is, you can think logically and you know the difference between your hard drive and your RAM.

And please, it's called "REPEATEDLY_EXECUTE". The word appears seven times in the code you've posted, yet you still can't spell it correctly. Programming/scripting is all about correct spelling.

You want us to help you, so please put some effort in it yourself.

Ashen

Khris, have YOU read the rules lately? The part about being abke to act like a moderator in this forum has been removed, so please don't in the future.

However, since you've posted:
Baily, nothing he's said is actually wrong. You don't seem to have read the forum rules, or to be putting any real effort in for yourself. Please, sort that out before posting again.

Quote
well, i took the code I put in out
What's the point of posting all that, then? I asked for the rep_ex code to see what was wrong - if you take it out there's nothing to see, and there was no need for ALL that code anyway.

Quote
Does any1 know the script I should post and where (more spacificly), because nomatter what script i put in my games, it always comes up with an error message. Can someone just solve my question about how to make my squirrel randomly run around?
KhrisMUC's code should work perfectly. But then, so should Creators if you'd put it in rep_ex properly.
I know what you're thinking ... Don't think that.

Khris

Quote from: Ashen on Tue 20/03/2007 10:09:04
Khris, have YOU read the rules lately? The part about being abke to act like a moderator in this forum has been removed, so please don't in the future.
I won't, but just for the record: I object the removal of that part. :=

Baily63

Kris ty that's what I wanted, but it no working :(

Khris

*sigh*

Error message?
Or doesn't it work at all? Or just not the way you want it to work?

MORE INFO.

Baily63

No error message, just that the squirrel in't walking around

nihilyst

Did you set up walkable areas? And if you have, did you put Squirrel onto it? Because if it isn't on a walkable area, it won't walk.

Baily63

#15
Is that right? Darn, that doesn't help. Oh well, i'll do anyway. Ill post the results.

EDIT:
Yeh! TY ALL!  ;D ;D ;D

Edit by Ashen: DON'T DOUBLE POST.

SMF spam blocked by CleanTalk