Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Crash when NPC is reset when walking  (Read 12493 times)

0 Members and 1 Guest are viewing this topic.

Eshaktaar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 14
    • View Profile
Crash when NPC is reset when walking
« on: February 25, 2008, 01:14:50 AM »

Hello, first post here!

I'm currently experimenting with WME to get a feel for what it can do, and I seem to have hit a bug:

I have an NPC that walks around the scene (inside an endless loop). When the player clicks on the NPC, I want the NPC to stop what she's doing until the player actor has reached her position. After a short talk, the NPC will then resume her walk. To stop the NPC, I call her Reset() function. Then the player actor says a line, and when the NPC is supposed to answer, the game shuts down.

I could recreate the bug in a simpler example here (NPC's script):

Code: [Select]
#include "scripts\base.inc"

this.GoTo(400, 470);

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
this.Reset();
actor.GoTo(this.X, this.Y);
this.GoTo(400, 470);
}

When I click on the NPC she stops and waits for the player actor to reach her position. But when the NPC is supposed to continue walking, the game crashes. Note that this only happens if I click on the NPC while she is still walking. If she stands still, the code works.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Crash when NPC is reset when walking
« Reply #1 on: February 25, 2008, 08:39:53 AM »

could you please post all relevant scripts including the endless loop?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Eshaktaar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 14
    • View Profile
Re: Crash when NPC is reset when walking
« Reply #2 on: February 25, 2008, 12:51:48 PM »

Certainly, the endless loop is also in the NPC's script:

Code: [Select]
#include "scripts\base.inc"

walkAround();

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
this.Reset();
actor.GoTo(this.X, this.Y);
this.GoTo(200, 470); // crash happens here
}

////////////////////////////////////////////////////////////////////////////////
on "Talk"
{
this.Reset();
actor.GoTo(this.X, this.Y);
actor.Talk("Hey there!"); // crash happens before this line appears on screen
this.Talk("Go away!");
walkAround();
}

// LOOP
function walkAround()
{
while (true)
{
this.GoTo(200, 470);
Sleep(5000);
this.GoTo(600, 470);
Sleep(5000);
}
}

My first description was inaccurate, I noticed: In the Talk event the crash happens before the player actor can say "Hey there!", right after "actor.GoTo(this.X, this.Y);". If I remove the line "actor.GoTo(this.X, this.Y);" in the Talk event, the player actor can say her line, and then the crash occurs.

If I comment out "this.Reset();" and "walkAround();" in the Talk event, no crash happens. In this case, however, I can talk to the NPC only once, and then she becomes "inactive" and talking to her or left-clicking on her does nothing (even though her caption still appears when the mouse is over her).
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Crash when NPC is reset when walking
« Reply #3 on: February 25, 2008, 12:58:32 PM »

Thanks, Eshaktaar. I'll see if I can reproduce the crash.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eshaktaar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 14
    • View Profile
Re: Crash when NPC is reset when walking
« Reply #4 on: March 04, 2008, 09:10:34 AM »

Thanks. I could reproduce the crash on two different machines (one with XP and one with Vista).
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Crash when NPC is reset when walking
« Reply #5 on: March 15, 2008, 01:29:00 PM »

Ok, I removed the crash, but this script won't work as you expect it anyway. Calling Reset() does actually terminate all the scripts currently waiting for the object being reset. So in this case, calling Reset() while the NPC is walking will terminate the whole script (the script is waiting for the actor to stop walking). You might want to redesign the script, to call the walking in a separate "thread". See this script for an inspiration. Notice the "idle" event, which can be safely terminated, while the rest of the script continues to work.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eshaktaar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 14
    • View Profile
Re: Crash when NPC is reset when walking
« Reply #6 on: March 20, 2008, 02:47:34 PM »

Cool, thank you. I'll try to implement the idle behaviour according to the Wiki example.
Logged
 

Page created in 0.035 seconds with 19 queries.