Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: DeleteEntity error, even though code works  (Read 3661 times)

0 Members and 1 Guest are viewing this topic.

sunrosea

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 12
    • View Profile
DeleteEntity error, even though code works
« on: September 09, 2012, 11:15:54 AM »

Hi!

I wanted to have an animated sprite in the beginning of the game, without the actor, because it is supposed to be the actor lying down on the ground.
So I decided to load the actor after the sprite have done its job, and so this is what I came up with:
game.script
Code: [Select]
// which scene to load?
Game.ChangeScene(Game.StartupScene);
//create animated sprite on scene
var wakeupanim= Scene.CreateEntity("wakeupanimation");
wakeupanim.SetSprite("Animations\wakeupscene1.sprite");
wakeupanim.X=280;
wakeupanim.Y=521;
//Let animated sprite animate before fade out
Sleep(5000);
//Delete sprite from scene
wakeupanim.DeleteEntity("wakeupanimation");
Scene.FadeOut(100);
Game.ChangeScene(Game.StartupScene);
//Load main actor
actor = Game.LoadActor("actors\Naomi\Naomi.actor");
Game.MainObject = actor;

This works totally fine. But I still get an error saying:
 "12:08:26:  Runtime error. Script 'scripts\game.script', line 39
12:08:26:    Call to undefined method 'DeleteEntity'. Ignored."

It does delete the sprite anyways, because its not there once the scene is loaded again with the actor.
But I'm just thinking it might ruin other things with the game further on, is there something i need to fix so that i do not get the error?

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: DeleteEntity error, even though code works
« Reply #1 on: September 09, 2012, 10:29:07 PM »

correct could would be:

Code: WME Script
  1. Scene.DeleteEntity(wakeupanim);
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

sunrosea

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 12
    • View Profile
Re: DeleteEntity error, even though code works
« Reply #2 on: September 10, 2012, 06:44:58 AM »

Ah right, I see. Thank you :)

I noticed tho that i get another error, thats only there when I have that code in the file. If i remove it, it doesn't get the error.
I removed the deleteEntity in any case because when i reload the scene the entity seems to disappear on its own.

The error is:
07:34:54:  Runtime error. Script 'scenes\Room\scr\scene_init.script', line 5
07:34:54:    Call to undefined method 'SkipTo'. Ignored

I have not edited the scene_init.script, but it doesn't seem to be that file having errors, but the game.exe doing something to make the engine say there's an error there.

Here's what the whole coding looks like so far for the game.script file:
Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"

// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;


// load the right-click menu
global WinMenu = Game.LoadWindow("interface\menu\menu.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetControl("caption");


global MenuObject = null;






// run the "game loop" script
Game.AttachScript("scripts\game_loop.script");




//create animated sprite on scene
Game.ChangeScene(Game.StartupScene);
var wakeupanim= Scene.CreateEntity("wakeupanimation");
wakeupanim.SetSprite("Animations\wakeupscene1.sprite");
wakeupanim.X=280;
wakeupanim.Y=521;
wakeupanim.Scale=100;
//Let animated sprite animate before fade out
Sleep(5000);
//Delete sprite from scene
Scene.FadeOut(100);
Game.ChangeScene(Game.StartupScene);
//Load main actor
actor = Game.LoadActor("actors\Naomi\Naomi.actor");
Game.MainObject = actor;


actor.SubtitlesPosX = 0;
actor.SubtitlesPosY = 550;
actor.SubtitlesWidth=1324;

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
    // clicking an inventory item
    if(ActObj.Type=="item" && Game.SelectedItem==null)
    {
      Game.SelectedItem = ActObj;
    }
    // using an inventory item on another object
    else if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
    {
      var Item = Game.SelectedItem;
      if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
      else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
      else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
      else actor.Talk("I can't use these things together.");
    }
    // just a simple click
    else ActObj.ApplyEvent("LeftClick");

  }
  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}



////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }

  var ActObj = Game.ActiveObject;

  // is the righ-click menu visible? hide it
  if(WinMenu.Visible == true) WinMenu.Visible = false;
  else if(ActObj!=null)
  {
    // if the clicked object can handle any of the "verbs", display the right-click menu
    if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
    {
      // store the clicked object in a global variable MenuObject
      MenuObject = Game.ActiveObject;
      var Caption = WinMenu.GetControl("caption");
      Caption.Text = MenuObject.Caption;

      // adjust menu's position
      WinMenu.X = Game.MouseX - WinMenu.Width / 2;
      if(WinMenu.X < 0) WinMenu.X = 0;
      if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;

      WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
      if(WinMenu.Y<0) WinMenu.Y = 0;
      if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;

      // and show the right-click menu
      WinMenu.Visible = true;

      // stop the actor from whatever he was going to do
      actor.Reset();
    }
    // no verbs supported, no menu is needed; just send the RightClick event to the object
    else ActObj.ApplyEvent("RightClick");
  }
}


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE || Keyboard.KeyCode==VK_F1)
  {
    // load and display the main menu window
    WinCaption.Visible = false;
    var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
    WinMainMenu.Center();
    WinMainMenu.GoSystemExclusive();
    Game.UnloadObject(WinMainMenu);
  }
}


////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  WinCaption.Visible = false;
  var WinQuit = Game.LoadWindow("interface\system\quit.window");
  WinQuit.Center();
  WinQuit.GoSystemExclusive();

  // and if the user selected Yes
  if(WinQuit.xResult)
  {
    // quit the game
    Game.QuitGame();
  }
  // otherwise just unload the quit window from memory
  else Game.UnloadObject(WinQuit);
}
« Last Edit: September 10, 2012, 06:51:42 AM by sunrosea »
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: DeleteEntity error, even though code works
« Reply #3 on: September 11, 2012, 03:12:25 PM »

If you read correctly the error you are getting, you can see, that the problem is in the file:

scenes\Room\scr\scene_init.script

which is a default template file for a new scene (you can change those too btw.). Default template reference actor which is positioned to some place in the scene (hence SkipTo).

Problem with your code is that you load your code AFTER scene change:

Code: WME Script
  1.  
  2. //Load main actor
  3. actor = Game.LoadActor("actors\Naomi\Naomi.actor");
  4. Game.MainObject = actor;
  5.  
  6. actor.SubtitlesPosX = 0;
  7. actor.SubtitlesPosY = 550;
  8. actor.SubtitlesWidth=1324;
  9.  

your code should rather be:

Code: WME Script
  1. //Load main actor
  2. actor = Game.LoadActor("actors\Naomi\Naomi.actor");
  3. Game.MainObject = actor;
  4.  
  5.  
  6. actor.SubtitlesPosX = 0;
  7. actor.SubtitlesPosY = 550;
  8. actor.SubtitlesWidth=1324;
  9.  
  10.  
  11.  
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet
 

Page created in 0.078 seconds with 25 queries.