Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Pages: 1 2 [All]

Author Topic: How to check if a sprite is running and stop it?  (Read 11756 times)

0 Members and 1 Guest are viewing this topic.

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
How to check if a sprite is running and stop it?
« on: March 08, 2008, 05:28:51 PM »

Hi all

I set a sprite running in an entity like this:
a = "MySprite.sprite";
b = Scene.GetNode("SpritePlace");
b.SetSprite(a);

Which works fine, but I can't figure out how to check if the sprite is running and then stop it. I guess it must be something to do with querying the entity? I've put 'Stop Sprite running' into the forum, but nothing seems to point me to the answer. Can anybody help?

Thanks

Kaz
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #2 on: March 08, 2008, 06:40:12 PM »

Thanks Metamorphium

The effect I'm trying to achieve is "If this, then do that - if any sprite is running in node subx, stop it." I tried to make the code you pointed me work like an 'if', thus:
b = null;
a = Scene.GetNode("subx");
b = a.GetSpriteObject();
if(b != null)
  {
  b.Reset();
  }
Doesn't work, the sprite in subx keeps playing. Thanks for the assistance and forgive me for being unable to implement it. Any pointers gratefully accepted.

Regards

Kaz
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #3 on: March 09, 2008, 01:00:55 PM »

Reset() doesn't prevent the sprite from starting to play over again. You might need to do something like:

b.Reset();
b.Pause();

Or just b.Pause() for that matter. Depends on the effect you need to achieve.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #4 on: March 16, 2008, 09:22:41 AM »

Actually, what I'm mainly looking for is what to check to see if the sprite is running. Can anybody tell me plase what should be in my
'if' statement to test whether or not a sprite is running?

Thanks
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 352
    • View Profile
    • Jyujinkai's WME Development Blog
Re: How to check if a sprite is running and stop it?
« Reply #5 on: March 16, 2008, 09:33:47 AM »

i keep reading your avatar as "studio afterbirth" lol sorry just thought it was funny... must be my dyslexia.
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #6 on: March 16, 2008, 10:01:15 AM »

The sprite is always running, unless it finished (and doesn't loop) or unless you paused it. So the "if" would look something like this:

Code: WME Script
  1. var Sprite = SomeEntity.GetSpriteObject();
  2. if(!Sprite.Finished && !Sprite.Paused) // NOT finished AND NOT paused
  3. {
  4.   // sprite is animating
  5. }
  6.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #7 on: March 16, 2008, 02:13:55 PM »

Hi Mnemonic

Thanks for that. Put that way, looks obvious :-)

Can you please point me to where I'd find that in the documentation? I'd prefer not to ask daft questions when the answer is already catered for in the script engine.

Thanks

Kaz
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #8 on: March 16, 2008, 02:29:33 PM »

The sprite properties are described in Scripting in WME -> Script language reference -> Sprite object.
But don't worry about asking questions. That's what the forum is for.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #9 on: March 16, 2008, 03:17:49 PM »

Nope. that didn't work

This sprite is relentless. No matter what I throw at it, it just keeps going. It's a message on an answering machine, subtitles and sound in one sprite. I put it into Node "subx" with a 'SetSprite' and then check if it is running- with a view to stopping it if it is. My code is:

// Are we listening to a message?
a = Scene.GetNode("subx");
m = ItemNormal.GetSpriteObject();
if(m.Finished == false && m.Paused == false)
  {
  Game.Msg("I'm not finished");
  Game.StopSound();
  m.Reset;
  m.Pause;
  }
But it just trundles on. This is how much hair I had before I started writing this script.  O0 This is me now.  ???  I tried to copy the hints Mnemonic and Metamorphium gave me and I've read everything I can find. What am I doing wrong?

Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #10 on: March 16, 2008, 03:23:51 PM »

Oops

Din't complete edit b4 sending - code should read

// Are we listening to a message?
a = Scene.GetNode("subx");
m = a.GetSpriteObject();
if(m.Finished == false && m.Paused == false)
  {
  Game.Msg("I'm not finished");
  Game.StopSound();
  m.Reset;
  m.Pause;
  }
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How to check if a sprite is running and stop it?
« Reply #11 on: March 16, 2008, 03:27:52 PM »

does the message appear? Does the script run at all? Any errors in the log file?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #12 on: March 16, 2008, 03:29:28 PM »

So the message doesn't display?
Those two last lines should read:

m.Reset();
m.Pause();

They are methods, not properties, therefore they require parameters even if there are none (-> empty parenthesis).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #13 on: March 16, 2008, 04:05:31 PM »

Oops with the brackets. Put them in, but the sprite still rolls merrily on. The script is running because I see the Game.Msg.

I've even tried disabling the Node that carries the sprite, but the message and subtitles keep coming no matter how often I go through the routine.
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #14 on: March 16, 2008, 04:17:51 PM »

Well I tried the following code in WME Demo and it definitely does work:

Code: WME Script
  1.   var Fan = Scene.GetNode("fan");
  2.   var Sprite = Fan.GetSpriteObject();
  3.  
  4.   if(!Sprite.Finished && !Sprite.Paused)
  5.   {
  6.     Sprite.Reset();
  7.     Sprite.Pause();
  8.   }
  9.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #15 on: March 16, 2008, 05:02:35 PM »

Hi,

I've attached the whole script - because now the game just gives me a run-time error and says that 'Pause' is not defined.

I'm completely at a loss.

#include "scripts\base.inc"
//
global gNextMessageToPlay;
global gHeardMessage1;
var a;
var Sprite;
Game.AttachScript("scenes\04_Lounge\ANSAPHONE\scr\MessagePlay.script");
//
on "LeftClick"
  {
  // Disable exit
  a = Scene.GetNode("zoom_out");
  a.Active = false;
  //
  Game.PlaySound("sounds\LittleSwitch.ogg");
  Sleep(500);
  // Are we listening to the bleep?
  a = Game.IsMusicChannelPlaying(1);
  if(a == true)
    {
    Game.StopMusicChannel(1);
    }
  //
  // Are we listening to a message?
  a = Scene.GetNode("subx");
  Sprite = a.GetSpriteObject();
  if(!Sprite.Finished && !Sprite.Paused)
    {
    Game.Msg("I'm not finished");
    Sprite.Pause();
    }
  else
    // if we can't hear a message, time to play one
    {
    if(gHeardMessage1 == false)
      {
      gNextMessageToPlay = 1;
      Game.MessageNumber();
      }
    Game.PlayMessage();
    }
  }
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How to check if a sprite is running and stop it?
« Reply #16 on: March 16, 2008, 06:21:04 PM »

are you sure the entity in question is Sprite Entity and is called subx (don't forget it's case SENSITIVE)?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #17 on: March 17, 2008, 02:46:37 PM »

Hi Metamorphium,

Yes I'm sure about that. The code that runs the sprite is in another part of the Attached script, and it must be working, because the sprite plays its designated mixture of subtitles and voiceover:
var Sprite;
var a;
global gNextMessageToPlay;
  if(gNextMessageToPlay == 1)
    {
   gHeardMessage1 = true;
    Sprite = "scenes\04_Lounge\ANSAPHONE\TommyANSA1.sprite";
             a = Scene.GetNode("subx");
   a.SetSprite(Sprite);
   a.Active = true;
    }
So if I'd got the case wrong relative to the scene entity, it wouldn't play, let alone stop, right?

Cheers
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #18 on: March 21, 2008, 08:47:48 AM »

I've given up on this one. I'll find another way of playing the messages. Still don't know why I couldn't control the sprite though, which is disconcerting.
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re: How to check if a sprite is running and stop it?
« Reply #19 on: March 21, 2008, 09:36:15 AM »

As a last resort you can upload the sources of a simple test scene. It's always the best method to check what's going on. And if you don't want to do this in public you can send the link in a pm to Mnemonic.
Logged
fl*p

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How to check if a sprite is running and stop it?
« Reply #20 on: March 21, 2008, 11:27:47 AM »

or send a PM to me for that matter. The problem will be elsewhere IMO and having some minimalistic testing scene would help.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #21 on: March 22, 2008, 01:56:47 PM »

Interesting new development. Thanks for the idea to create a minigame, it's definitely thrown up something...

In order to create the minigame, I had to rebuild the sprite. Half a dozen timed frames, with a sound file connected to the first frame. Set that running in SpriteEdit. Then press the 'stop' button. The animation stops, but the sound keeps going! So even SpriteEdit cannot stop the attached sound - so I'm less surprised now that I couldn't stop the sprite in the game either. Could that be a bug?

In any case, although sprites would be a convenient way of handling this scene, the sound handling seems suspect. I guess I'll take the sound out and control it separately with a MusicChannel. That way I can do an IsMusicChannel and if it's true, do a StopMusicChannel at the same time as an ent.Active=false on the node carrying the subtitles (after resetting the node's sprite of course).

Thanks for all your help guys.

Cheers

Kaz
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How to check if a sprite is running and stop it?
« Reply #22 on: March 22, 2008, 09:39:15 PM »

is the sound ogg or wav?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #23 on: March 22, 2008, 10:51:25 PM »

I didn't realize Kaz was talking about sprite's sound all the time.
Now I modified the Sprite.Reset() method so that it also stops all sounds being played by the sprite.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #24 on: March 23, 2008, 12:02:19 PM »

Hello M and Mn

The sound is an ogg. Thanks for looking at the method.

One last thing: what do I need to do to stop getting this:

11:00:34:  Runtime error. Script 'scenes\04_Lounge\ANSAPHONE\scr\Play.script', line 33
11:00:34:    Call to undefined method 'Reset'. Ignored.


from this code?
   a = Scene.GetNode("subx");
   Sprite = a.GetSpriteObject();
   Sprite.Reset();


Thanks

Kaz
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to check if a sprite is running and stop it?
« Reply #25 on: March 23, 2008, 12:05:49 PM »

You'll get this error if the sprite object reference isn't valid. Try this:

if(Sprite != null) Sprite.Reset();
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Kaz

  • Arberth Studios
  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 228
  • The story is the game
    • View Profile
    • Info on 'Rhiannon' & 'Coven'
Re: How to check if a sprite is running and stop it?
« Reply #26 on: March 23, 2008, 12:24:29 PM »

Ah, I hadn't thought of that, thanks. Although I guess it would be better if my code was written so I didn't make the error of addressing an empty Node in the first place!  :-[

I'll recheck my logic.
Logged
\"Fans of popular horror adventures like Scratches and Barrow Hill should start bracing themselves for another haunting experience, as independent developer Arberth Studios has announced production on its debut title Rhiannon - Curse of the Four Branches.\" - AdventureGamers.com
Pages: 1 2 [All]
 

Page created in 0.07 seconds with 21 queries.