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: Removing an entity from the scene  (Read 3316 times)

0 Members and 1 Guest are viewing this topic.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Removing an entity from the scene
« on: December 06, 2008, 06:57:58 PM »

I have an entity loaded in the ini script of a scene.  As soon as he's finished doing his job (talking and giving the player something), I want to get rid of him.  But I get the error that the reference to him is undefined.

I get that error a lot and sometimes I can get rid of it and sometimes not.

In this case, since he's not a scene node, I don't know how to refer to him.

The way I refer to him when he's loaded is:

global kolobok = Scene.LoadEntity("entities\kolobok\kolobok.entity");
kolobok.SkipTo(630, 316);

If I refer to him that way when I'm trying to get rid of him, I just load another copy of him.  : |

It would be really helpful if someone could post some sort of standard way of defining a global something.

For example to define a layer I know it's
var layer = Scene.GetLayer("whatitis");

and for a scene node

var node = Scene.GetNode("whatitis");

if I'm in a window I know how to get the controls to define them as a variable
but if I'm outside that window, I'm lost as to how to refer (call) (access) those contols from a different window

This is almost 90% of my problems right now.  : )
« Last Edit: December 06, 2008, 07:02:34 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Removing an entity from the scene
« Reply #1 on: December 06, 2008, 07:58:47 PM »

It must be
Game.DeleteEntity();

If you want this to happen after the entity has done some thing,
you must add at the entity's script and at the end of each method some thing like:
Game.DeleteEntity(this);

Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Removing an entity from the scene
« Reply #2 on: December 07, 2008, 12:05:32 AM »

I tried this in a variety of ways--including

Code: WME Script
  1. on "Goodbye"
  2. {       
  3. var e = this.GetControl("Buttop2");
  4. e.ParentNotify = false;
  5. e.Text = "";
  6. Game.DeleteEntity("entities\kolobok\kolobok.entity");
  7.   this.Close();
  8.   }
  9.  
  10.  

I put the Delete part before this.Close(), cause once the windows closed, he should be gone but he remains.

Thank you for your help.  This script is on a button in a Window and he's loaded through the script.ini file of the scene.  It just won't work for some reason. 

I tried Game.DeleteEntity("kolobok");
I tried Game.DeleteEntity(kolobok);
I tried Game.DeleteEntity("kolobok.entity");
and the above.
« Last Edit: February 19, 2009, 08:31:40 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Removing an entity from the scene
« Reply #3 on: December 07, 2008, 09:35:21 AM »

Let me briefly explain the principles. There're quite simple:

Everything you create in SceneEdit (layers, entities, regions...) is managed by Scene. When you change scene, the old scene is destroyed and the new one is loaded. All automatic. You can add new stuff to scene in scripts, using Scene.LoadEntity(), Scene.LoadActor(), Scene.CreateEntity() etc. Objects created that way become part of the scene and they are managed by scene as well.

However, you can also create "global" objects, owned by the Game, using script methods like Game.LoadEntity(), Game.LoadWindow() etc. Objects created this way are never released automatically and YOU are responsible for destroying them when you no longer need them. Using Game.UnloadObject().

Now, to be able to destroy them, you need a reference to these objects. You cannot destroy them using their filename (it's logical, when you think of it, you can have ten objects created by loading the same file).
So, you'll need to store the reference when you are creating the object.

  var SomeEntity = Game.LoadEntity("some\path.entity");

The "SomeEntity" variable now contains the reference to the newly created entity, and you can pass the reference to UnloadObject later.

  Game.UnloadObject(SomeEntity);
 
If you need to share the same reference between multiple scripts (like, one scripts creates the object, but other script destroys it), you will need to use global variable. A global variable can be accessed by any script, you just need to declare it before using it.

Code: WME Script
  1. // this line says: "I'll be using a global variable called SomeVariable, allow me access to it"
  2. global SomeVariable;
  3.  
  4.  
  5. // now I can read and write to the global variable
  6. // if other scripts declare it using "global SomeVariable;",
  7. // they will get access to the same variable
  8. SomeVariable = Game.LoadEntity("some\path.entity");
  9.  

So the above script loaded an entity into a global variable. If other script needed to access the entity, or, say, destroy it, it would contain:

Code: WME Script
  1. // get me the global variable, no matter who created it
  2. global SomeVariable;
  3.  
  4. // and destroy its contents
  5. Game.UnloadObject(SomeVariable);
  6.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Removing an entity from the scene
« Reply #4 on: December 07, 2008, 03:29:09 PM »

Thank you for the detailed explanation.  It's very helpful but I still can't get rid of the little runt.

This is my scene.init script--it's on a button--the goodbye button that closes my dialogue box.

global kolobok = Scene.LoadEntity("entities\kolobok\kolobok.entity");
kolobok.SkipTo(630, 318);

This is the script in the script file attached to the dialogue box.

Code: WME Script
  1.  
  2. on "Goodbye"
  3. {       
  4. var e = this.GetControl("Buttop2");
  5. e.ParentNotify = false;
  6. e.Text = "";
  7. // and destroy its contents
  8.   this.Close();
  9.   global kolobok;
  10.   Scene.UnloadObject("entities\kolobok\kolobok.entity");
  11.    
  12.   }
  13.  
  14.  

I tried putting Scene.UnloadObject before this Close but still he's staring me in the face.   I don't get a script error--he just doesn't go away.  I'll try some more with this later tonight.  Thanks. 
« Last Edit: February 12, 2009, 10:46:35 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Removing an entity from the scene
« Reply #5 on: December 07, 2008, 05:10:31 PM »

Like I said, reference, not filename.

global kolobok;
Scene.UnloadObject(kolobok);
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Removing an entity from the scene
« Reply #6 on: December 07, 2008, 07:03:17 PM »

Yes, now it works perfectly.  Thanks, Mnemonic.   :)
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 351
    • View Profile
    • Jyujinkai's WME Development Blog
Re: Removing an entity from the scene
« Reply #7 on: January 04, 2009, 08:57:19 AM »

I am having the same problem here....

In BASE.INC
Code: WME Script
  1. global LoadH;

elsewhere in another script latter on is....
Code: WME Script
  1. LoadH = Game.LoadEntity("entity\H\H.entity");

In another place i am trying to unload this thing.. with...
Code: WME Script

But that line above give me a syntax error.
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: Removing an entity from the scene
« Reply #8 on: January 04, 2009, 09:32:19 AM »

That line is syntactically correct, as far as I can tell. If you are getting *syntax* error, it must be somewhere else in your script.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.047 seconds with 25 queries.