Idle view with wandering character

Started by Duckbutcher, Fri 16/03/2007 14:05:44

Previous topic - Next topic

Duckbutcher

I've been trying to have a character wander from one point to another, scribble something on a notepad (idle view) and then wander back and do the same thing.

So far, I've tried:

if (character[GRYSON].walking != 1) {
  MoveCharacter (GRYSON, 228, 117);
  MoveCharacterPath (GRYSON, 139, 114);
  MoveCharacterPath (GRYSON, 228, 117);

Which makes the character move back and forth. However, I'm having trouble a) getting this to run indefinitely (if I put it in 'repeatedly_execute' he just moonwalks on the spot, I put it in 'player enters room' and he stops once the script is done) and b) getting him to stop and go idle between movements. I've tried using:

character[GRYSON].SetIdleView(94, 1);

But the game ignores it. Can anyone help? I admit I might be barking up the wrong tree here, I'm still new to scripting so might be missing something basic.

Ashen

#1
It's not clear in the manual, but AFAIK, character[].walking isn't a boolean value. It returns 0 when the character isn't walking, and non-zero when they are -  just because Gryson is walking, it doesn't mean it'll always be 1. So it'll be restarted over and over, leading to the 'moonwalking' effect. It works OK if you just replace '!= 1' with '== 0'. However, that's only half your problem, right?

I think it's 'ignoring' the SetIdleView bit because he's never actually idle - as soon as he gets to one point, he should immediately start off again to the next. No pause, no chance for the Idle animation to run. Using a variable to hold him in place for a while might work, e.g.:

Code: ags

//top of room script
int GryWait = 10;

// player enters room interaction
cGryson.SetIdleView(94,0);

// rep_ex
if (cGryson.Moving == true) GryWait = 10;
else {
  if (GryWait > 0) GryWait --;
  else {
    if(cGryson.x == 228) cGryson.Walk(139,114);
    else cGryson.Walk(228, 117);
  }
}

(Change the GryWait = 10, to have him animate for a longer or shorter time.)

I've updated all the code to OO-style - you where mixing old and new code which, while it won't cause any errors, is bad practice.

I think the CharacterControl module allows you to easily set up background actions like this - if you're likely to need this for more than one character, or in a couple of different rooms, it might be a better idea to look into that.
I know what you're thinking ... Don't think that.

Duckbutcher

#2
Thanks for the info. I can't get the idle code to work though, it says "Grywait" is undefined.

Just to clarify, this is what my room script now looks like.

// room script file
int GryWait = 10;Ã, 
}

#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for Room: Player enters room (before fadein)
cGryson.SetIdleView(94,0);
Ã, 
}Ã, 

#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
Ã,  // script for Room: Repeatedly execute
if (character[GRYSON].walking == 0) {
Ã,  MoveCharacter (GRYSON, 228, 117);
Ã,  MoveCharacterPath (GRYSON, 139, 114);
Ã,  MoveCharacterPath (GRYSON, 228, 117);
if (cGryson.Moving == true) GryWait = 10;
else {
Ã,  if (GryWait > 0) GryWait --;
Ã,  else {
Ã,  Ã,  if(cGryson.x == 228) cGryson.Walk(139,114);
Ã,  Ã,  else cGryson.Walk(228, 117);
Ã,  }
}

Ã, 
}
#sectionend room_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE

Any ideas?

And thanks, the 'wandering' code now works fine.

Ashen

There's a closing brace after the declaration line - if it's there in the actual script, and it's not givng you an 'unexpected }' error, GryWait must be being declared inside a function. Is that the whole of the room script (nothing before //room script file)? Which line is givng the error?

I'm not sure what could be causing it. It looks like you've got a mismatched brace / nesting functions error with the repeatedly_execute function - but that wouln't cause that error message. Also, you shouldn't need the character[GRYSON].walking condition anymore, so you can delete it. Your rep_ex function should look like:
Code: ags

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for Room: Repeatedly execute
  if (cGryson.Moving == true) GryWait = 10;
  else {
    if (GryWait > 0) GryWait --;
    else {
      if (cGryson.x == 228) cGryson.Walk(139,114);
      else cGryson.Walk(228, 117);
    }
  } 
}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE


Wait - is that exactly how the room script looks? If the int declaration was after the rep_ex that'd explain the error you're getting, AND why you're not getting the two I'd expect...
I know what you're thinking ... Don't think that.

Duckbutcher

#4
Scrach that, it looks like it's sorted now. It was just me being a dope and not putting the int in the right place. Thanks a lot for your help!

Duckbutcher

Sorry, I'm back again! I can't stop him "idling" inbetween lines of conersation. I've tried "Disable Idle Animation" function but it doesn't seem to work. I assume it's because of the code being in the "Repeatedly Execute" function, so the code is repeatedly being called, even after it has been disabled. While this isn't a major problem, it does look a bit messy as the animation makes it looks as if my character is noting down everything the other character says in his jotter!

Any ideas?

Ashen

Another variable could be added, so the repeatedly_execute code is only executed (repeatedly) when you want it to be. Since the 'Disable Idle View' interaction sets the Character's Idle view to -1, you could check against that:
Code: ags

  if (cGryson.IdleView != -1) {
    if (cGryson.Moving == true) GryWait = 10;
    else {
      if (GryWait > 0) GryWait --;
      else {
        if (cGryson.x == 228) cGryson.Walk(139,114);
        else cGryson.Walk(228, 117);
      }
    }
 }


However, there's nothing in that code that would cause the animation to run - it gives the Idle animation a chance to run if it should, but if it's been disabled it shouldn't however long he stands around.

If the extra check doesn't work:
How and where are you disabling the Idle view? (Show the code and/or Interaction Editor commands used.) Oh, and is the conversation a Dialog, or Character.Say commands? (Not sure if that'd make a difference, but it might...)
I know what you're thinking ... Don't think that.

Sparky

If that doesn't work, you could create a boolean that is 0 during idle, and 1 during a conversation.

Creating a new variable
Code: ags
bool GryTalking = 0;


Addition to character script
Code: ags

GryTalking = 1;
// conversation starts here
GryTalking = 0;


Modification of the repeatedly_execute script
Code: ags
Ã,  if (GryTalking != 1) {
Ã,  Ã,  if (cGryson.Moving == true) GryWait = 10;
Ã,  Ã,  else {
Ã,  Ã,  Ã,  if (GryWait > 0) GryWait --;
Ã,  Ã,  Ã,  else {
Ã,  Ã,  Ã,  Ã,  if (cGryson.x == 228) cGryson.Walk(139,114);
Ã,  Ã,  Ã,  Ã,  else cGryson.Walk(228, 117);
Ã,  Ã,  Ã,  }
Ã,  Ã,  }

Duckbutcher

Quote from: Ashen on Thu 22/03/2007 00:10:08
Another variable could be added, so the repeatedly_execute code is only executed (repeatedly) when you want it to be. Since the 'Disable Idle View' interaction sets the Character's Idle view to -1, you could check against that:
Code: ags

Ã,  if (cGryson.IdleView != -1) {
Ã,  Ã,  if (cGryson.Moving == true) GryWait = 10;
Ã,  Ã,  else {
Ã,  Ã,  Ã,  if (GryWait > 0) GryWait --;
Ã,  Ã,  Ã,  else {
Ã,  Ã,  Ã,  Ã,  if (cGryson.x == 228) cGryson.Walk(139,114);
Ã,  Ã,  Ã,  Ã,  else cGryson.Walk(228, 117);
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
 }


However, there's nothing in that code that would cause the animation to run - it gives the Idle animation a chance to run if it should, but if it's been disabled it shouldn't however long he stands around.

If the extra check doesn't work:
How and where are you disabling the Idle view? (Show the code and/or Interaction Editor commands used.) Oh, and is the conversation a Dialog, or Character.Say commands? (Not sure if that'd make a difference, but it might...)


Ashen - I can't get that to work, it doesn't throw up any errors or anything, it just does the same thing.
The conversation is a dialogue and I'm using the interaction editor "disable idle view" command immediately before the dialogue is called, if that helps.

Sparky, where exactly does the bool GryTalking = 0; go?  Presumably the two GryTalking = commands would go either side of the dialogue being called.

Apologies if my questions seem obvious, I'm just getting to grips with scripting and hope to be proficient at it some day...thanks for your help guys.

Ashen

I didn't really think it'd work because - as I said - that code is nothing to do with actually running the Idle animation. (Also, I'm not sure if rep_ex runs during Dialogs, or if they're completely blocking...)
Sparky's idea won't work as it is. Dialog.Start() is queued until after the rest of the current block of script has run, so it'd actually be:
Code: ags

GryTalking = 1;
GryTalking = 0;
// conversation starts here


Which would obviously have no effect. You could use dialog_request to run the GryTalking = 0; line from the dialog, when it's over. (Sparky,, sorry if that's what you meant, but i wasn't very clear.) Still, it mightn't have any more effect than checking the Idle view.

How about simply extending the Idle delay for the character, instead of disabling it?
Code: ags

//In the Character interaction script
cGryson.SetIdleView(94,30);
dGryson.Start(); // Or whatever the Dialog is called

//then, in the Room rep_ex
    if (cGryson.Moving == true) {
      GryWait = 10;
      cGryson.SetIdleView(94,0); // Should automatically reset it, when not in dialog
    }
    else {
      if (GryWait > 0) GryWait --;
      else {
        if (cGryson.x == 228) cGryson.Walk(139,114);
        else cGryson.Walk(228, 117);
      }
    }


Or, try disabling it from script, instead of using the Interaction Editor command (mixing IE and script can have odd results, like things running out of order, etc).
If it still doesn't work, show us the EXACT sequence of code and Interaction Editor commands you're using.
I know what you're thinking ... Don't think that.

Duckbutcher

Cracked it. thanks a lot for your help!


SMF spam blocked by CleanTalk