Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Placing items in a scene  (Read 6337 times)

0 Members and 1 Guest are viewing this topic.

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Placing items in a scene
« on: September 22, 2012, 10:41:11 AM »

Hello all,

I'm having issues with placing an inventory item in a scene. To give you some context, I have an inventory item (Some Dried Leaves) that need to be placed on a campfire (a regional entity in my scene). I'm using an entity file to do this currently, and the issues are:

Issue 1 - The entity originally did not appear when I set its active property to true (in the script below). I assumed this was because it was being "made active" behind the background layer, as the rest of the code worked. I'm not sure what I did, but now the entity appears, but now overlays all other entities including the actor. I only have 1 layer in my scene. I had originally tried the below code as a global variable in the game.script, but the entity would not appear at all, so I moved its declaration to the regional entity script (campfire.script). I can only assume this is what fixed it not appearing at all.

Issue 2 - The entity appears when the campfire code is executed, but it can then be seen in all other scenes in my game. I only want it to appear in one. How can this be done?

Please see a code snippit below to help:

In my campfire.script:

Code: WME Script
  1. //declare what DriedLeavesEntity is
  2. var DriedLeavesEntity = Game.LoadEntity("entities\driedleaves\driedleaves.entity");
  3. //make it inactive until we need it
  4. DriedLeavesEntity.Active = false;
  5.  
  6. //when dried leaves are used on the campfire
  7. on "leaves"
  8. {
  9.   //go to the campfire
  10.   actor.GoToObject(this);
  11.   //unselect the leaves item as we are using them
  12.   Game.SelectedItem = null;
  13.   //drop the item. We do not want to delete as the fire will only burn for a certain amount of time.
  14.   //If the player has not applied the chimney before the fire burns out, we need to be able to pick up the leaves again.
  15.   //whether the leaves can be picked up again are controlled by a separate global variable.
  16.   Game.DropItem("leaves");
  17.   //show the leaves on the campfire
  18.   DriedLeavesEntity.Active = true;
  19.   actor.Talk("It's the beginnings of a fire");
  20.   actor.Talk("I feel just like Bear Grylls");
  21. }
  22.  

and here's the driedleaves.entity definition:
Code: [Select]
ENTITY
{
  NAME="driedleaves"
  CAPTION="Dried Leaves"
  ACTIVE=TRUE
  X=667
  Y=385
  SCALABLE=FALSE
  INTERACTIVE=TRUE
  COLORABLE=FALSE
  SPRITE="entities\driedleaves\sprites\driedleaves.sprite"
 
  SCRIPT="entities\driedleaves\driedleaves.script"
  FONT = "fonts\outline_red.font"
}

After the above, I want to place a chimney over the leaves once they have been set on fire. I assume the answers to the above will allow me to do this also.

I could be going about this the completely wrong way and there may be a better way of doing this. Any help would be greatly received.

Squin
Logged

lof

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 19
  • A Leap Of Fate
    • View Profile
Re: Placing items in a scene
« Reply #1 on: September 22, 2012, 11:10:16 AM »

i use a different approach to do this.
i create the entities inside the scene and place them in the correct z-index order, after the background and before the floor, then i deselect the active box.

now when you want it to show in your scene just add this to the script

var DriedLeavesEntity = Scene.GetNode ("EntityName");
DriedLeavesEntity.Active=true;


usually you would like to create an extra BLOCK region around this entity, if you don't want the actor to step on it too.
« Last Edit: September 22, 2012, 11:12:45 AM by lof »
Logged

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Re: Placing items in a scene
« Reply #2 on: September 22, 2012, 11:28:30 AM »

How frustrating.

This is how I was originally going to do it, but I totally didn't realise there was an "active" check box next to the entity in the Scene editor!

What a numpty. That's a much easier way of doing it.

Thanks lof!

Squin
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: Placing items in a scene
« Reply #3 on: September 22, 2012, 05:35:12 PM »

You are accustomed to the fact that you can link scene entities to inventory, right?

http://docs.dead-code.org/wme/inside_inventory.html
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Squinage

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • Re:Gamed
Re: Placing items in a scene
« Reply #4 on: September 24, 2012, 02:19:57 PM »

Hi metamorphium,

Yes, I was aware of this, but thanks for the post.

The problem is that the source of the dried leaves item is not an entity, it's actually part of the background. The dried leaves item comes from a pile of dried leaves which is perpetual within the scene. The puzzle involves setting the dried leaves alight which then burn out if the player does not place another item on top of the fire. If the fire burns out, more dried leaves need to be picked up from the "infinite" pile of leaves to set fire to again.

I hope this provides a bit more context.

Squin
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: Placing items in a scene
« Reply #5 on: September 24, 2012, 07:35:57 PM »

Ah, I see. so is there anything else you need to help with or are you ready to rock'n'roll now? :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

bckpkol

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 1
    • View Profile
Re: Placing items in a scene
« Reply #6 on: April 21, 2014, 06:18:07 PM »

I'm wrote my own scripts doing the same thing.
First is a scene.script, here it is:
Code: [Select]
#include "scripts\base.inc"
//temporary variables
var itemname;
var itemcaption;
var itemsprite;
var itemtodrop;
var newent;
//item temporary store
global Xtosave;
global Ytosave;
global tulipXtosave;
global tulipYtosave;

//function that drop objects
function ObjectDrop(itemname, itemcaption, itemsprite)
{
//naturally, this checks if the item can "walk" into position :)
if (Scene.IsWalkableAt(Scene.MouseX, Scene.MouseY))
{
//actor walks somewhere around dropping object
actor.GoTo(Scene.MouseX+47, Scene.MouseY+47);
Sleep(400);
actor.TurnTo(DI_UPLEFT);
Sleep(400);
//turning off the interaction
Game.Interactive=false;
//setting up the objects
itemtodrop=actor.GetItem(itemname);
newent=Scene.CreateEntity(itemname);
//turning visibility off
newent.Active=false;
//setting parameters up
newent.Interactive=true;
newent.Scalable=true;
newent.Colorable=true;
newent.Caption=itemcaption;
newent.WalkToX=actor.X;
newent.WalkToY=actor.Y;
newent.WalkToDirection=actor.Direction;
newent.AttachScript("scripts\object_take.script");
//fix 1: saving position
Xtosave=actor.X-47;
Ytosave=actor.Y-47;
//setting last parameters up
newent.SkipTo(Xtosave, Ytosave);
newent.SetSprite(itemsprite);
if((itemtodrop.DisplayAmount==true)&&(itemtodrop.Amount>1))
{
//decreasing amount of the item by 1
itemtodrop.Amount=itemtodrop.Amount-1;
newent.Active=true;
}
else
{
//deleting item
itemtodrop.Amount=0;
newent.Active=true;
Game.SelectedItem=null;
Game.Interactive=true;
actor.DropItem(itemname);
}
Game.Interactive=true;
}
}

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // when the scene is left-clicked, just send the actor to the specified point
  actor.GoTo(Scene.MouseX, Scene.MouseY);
}

on "tulip"
{
//calling function that drop objects
ObjectDrop("tulip", "Tulip", "items\tulip.sprite");
//adding object coordinates into array
tulipXtosave.Push(Xtosave);
tulipYtosave.Push(Ytosave);
}

Second is a object_take.script, here it is:
Code: [Select]
#include "scripts\base.inc"

var itemtopick;
global tulipXtosave;
global tulipYtosave;

on "LeftClick"
{
//walk to previously setted coordinates
actor.GoToObject(this);
//turning off the lig... er, interaction
Game.Interactive=false;
//acquire, i.e. get item (even if it is already taken)
actor.TakeItem(this.Name);
//getting the object of the item
itemtopick=actor.GetItem(this.Name);
//increasing amount of the item by 1
itemtopick.Amount=itemtopick.Amount+1;
//deleting coordinates of this item
//(or maybe other identical, but that doesn't matter)
switch(this.Name)
{
case "tulip":
tulipXtosave.Pop();
tulipYtosave.Pop();
break;
case "default":
actor.Talk("An error happened. The item is not deleted correctly.");
actor.Talk("Look into object_take.script.");
break;
}
//turning on the interaction
Game.Interactive=true;
//entity (sprite container) should be deleted after all other things
Scene.DeleteEntity(this);
}

on "default-use"
{
Sleep(1);
}
Part of game.script:
Code: [Select]
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  var Item = Game.SelectedItem;
  if(ActObj!=null)
  {
    // clicking an inventory item (no item, item under cursor)
    if(ActObj.Type=="item" && Game.SelectedItem==null)
    {
      Game.SelectedItem = ActObj;
    }
    // using an inventory item on another object (object and item exist)
    else if(Item != null && Item!=ActObj)
    {
      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 (object exist, item is not)
    else ActObj.ApplyEvent("LeftClick");
  }
  else if(Scene.CanHandleEvent(Item.Name)) Scene.ApplyEvent(Item.Name);
  else
  { // else propagate the LeftClick event to a scene (object and item not exist)
    Scene.ApplyEvent("LeftClick");
  }
}
In items.items:
Code: [Select]
ITEM
{
   CURSOR_COMBINED = FALSE
   CAPTION = "Tulip"
   NAME = "tulip"
   IMAGE = "items\tulip.png"
   IMAGE_HOVER = "items\tulip.png"
   CURSOR = "items\tulip.sprite"
   FONT = "fonts\cmbr16.font"
   SCRIPT = "items\tulip.script"
   DISPLAY_AMOUNT = TRUE
   AMOUNT_ALIGN = "right"
}
Part of scene_init.script:
Code: [Select]
global tulipXInPOTION;
global tulipYInPOTION;
if (tulipXInPOTION==null) tulipXInPOTION=new Array();
if (tulipYInPOTION==null) tulipYInPOTION=new Array();
global tulipXtosave=tulipXInPOTION;
global tulipYtosave=tulipYInPOTION;
Exit region script:
Code: [Select]
#include "scripts\base.inc"

on "ActorEntry"
{
//getting temporal variables
global tulipXtosave;
global tulipYtosave;
//setting constant variables as temporal
global tulipXInPOTION=tulipXtosave;
global tulipYInPOTION=tulipYtosave;
Game.ChangeScene("scenes\Room\Room.scene");
}
And include file that restores items (#include "scripts\restore_items.inc" should be written in every scene_init.script)
Code: [Select]
var newent;
var am;
var itemname, itemcaption, itemsprite, itemarrayX, itemarrayY;

function ObjectPlace(itemname, itemcaption, itemsprite, itemarrayX, itemarrayY)
{
for(am=0;am<itemarrayX.Length;am=am+1)
{
//Re-creating entity
newent=Scene.CreateEntity(itemname);
//Turning visibility off
newent.Active=false;
//Setting up again
newent.Interactive=true;
newent.Scalable=true;
newent.Colorable=true;
newent.Caption=itemcaption;
newent.AttachScript("scripts\object_take.script");
newent.SkipTo(itemarrayX[am], itemarrayY[am]);
newent.WalkToX=newent.X+47;
newent.WalkToY=newent.Y+47;
newent.WalkToDirection=DI_UPLEFT;
newent.SetSprite(itemsprite);
//Turning visibility on
newent.Active=true;
}
}
ObjectPlace("tulip", "Tulip", "items\tulip.sprite", tulipXtosave, tulipYtosave);
« Last Edit: April 22, 2014, 12:15:47 PM by bckpkol »
Logged
 

Page created in 0.034 seconds with 20 queries.