[SOLVED]Need help with initiating code after EGO has been standing still

Started by Snake, Mon 07/04/2008 19:46:40

Previous topic - Next topic

Snake

Hi, guys,

I've been working on a small piece of code in the rep ex script in a room.

I'd like a timer to be set (ie; to 100) whenever the player has stopped moving.
When this timer ends I want to display a messege - unless he has moved again before the timer has run out.

I couldn't seem to work around my int standing always equaling 1 to process my code afterwords.

So I've been fiddling with it and it seems to half-assed work.

1. I don't understand why it is working since I want the code to run when the character is standing still, not moving...(as you'll see in my code below)

2. Everything seems to work fine except for when I press enter to exit the display messege. The timer doesn't seem to reset back to 100 after the messege. But if I walk again and stop, it works (even if I exit the messege using an arrow key).
Just not when I press enter.

Here's my code so you can take a lookie at what the hell I'm missing ;)
Code: ags

///STANDING STILL OR NOT
if (character[1].Moving==1) standing++;
if (character[1].Moving==0) standing=0;

if (standing!=0) {
  standing=0;
  SetTimer(17, 100);
}


if (IsTimerExpired(17)==1){
  Display("stuff");
  cpuscore++;
  standing++;
}



Thanks in advance for any help,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

TwinMoon

Totally unchecked code:

Code: ags

///STANDING STILL OR NOT
if (character[1].Moving==0) SetTimer(17, 100);

if (IsTimerExpired(17)==1){
  if (character[1].Moving==0) {
    Display("stuff");
    cpuscore++;
    standing++;
  }
}


It sets the timer when you're not walking, and if it's expired it checks again if he's still not walking.
Everytime you stand still the timer should be set again.

Snake

Hm, after I examined your code I was sure it wasn't going to work since I had already tried a couple similar structures. I tried anyway, and yeah, it didn't do anything.

It doesn't do anything since the timer is contantly being set to 100 if you're standing still - thus never timing out.

That's what my original problem was until I "solved it".

What I don't get is that it's totally reversed. I want to set standing to 1 if you are standing still and set it to 0 if you're moving. This never worked. After I paid a little more attention to it, I noticed that if you stayed still, no messege, but if you ran, the timer started and I got the messege. So for the hell of it I reversed it and it worked. I don't get it. character[1].Moving==1 does indeed mean that hje IS moving right?

And now the timer doesn't reset itself if you press "enter" after reading the display messege - but it does if you use an arrow to remove it.


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

TwinMoon

Quote from: Snake on Mon 07/04/2008 21:22:19
It doesn't do anything since the timer is contantly being set to 100 if you're standing still - thus never timing out.
Damn those computers that never understand anything! ;)

Quote from: Snake on Mon 07/04/2008 21:22:19
So for the hell of it I reversed it and it worked. I don't get it.

Well, this is the same thing. While he's moving the timer getz set all the time. If you stand still it'll still be running.

Hey, after reading back that last sentence, I think I got it:
after the Display command use SetTimer(17,100); again.

-TwinMoon

Khris

What about:
Code: ags
bool was_moving;

// rep_ex
  if (player.Moving) was_moving=true;
  else {
    if (was_moving) {
      SetTimer(17, 100);
      was_moving = false;
    }
  }

  if (IsTimerExpired(17)) {
    Display("stuff");
    SetTimer(17, 100);
  }


Alternative:
Code: ags
int mt;   // manual timer

// rep_ex
  if (player.Moving) mt = 100*GetGameSpeed();
  else mt--;

  if (mt==0) {
    Display("stuff");
    mt = 100*GetGameSpeed();
  }

SSH

Why bother with a timer?

Code: ags

if (player.Moving) standing++;
else standing=0;

if (standing>=100) {
  Display("stuff");
  cpuscore++;
  standing=0;
}

12

Snake

Ah ha! Great job, SSH. It works beautifully!

I almost tried it without a timer as well, but was fixated by getting this to work ;)

Thank you - puzzle solved,


--Snake

--EDIT----------//
The only thing I changed in the code was this, if (player.Moving) standing++;, to this, if (player.Moving==0) standing++; - since I wanted to test how long the player is standing there without moving.
I'll adjust the time later on today to get a feel of how long I want the wait to be before the messege.
-----------------//
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SMF spam blocked by CleanTalk