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

Author Topic: Learning scripting == actor.hasitem(item)  (Read 4353 times)

0 Members and 1 Guest are viewing this topic.

diegoquarantine

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 50
    • View Profile
    • Buenos Aires Quarantine Studio
Learning scripting == actor.hasitem(item)
« on: December 22, 2012, 06:23:37 AM »

Hi, I´m new in this engine and I already love it. It´s incredible how much you can do with so little.
Anyway, I´m learning the basic stuff of scripting usage and I can´t get right a simple item check. I want to check items before letting the actor leave the room. Here is the code. If anyone can tell me where I´m wrong here I would be very happy!.

Code: [Select]
on "LeftClick"

{
  actor.GoToObject(this);
 
}

if (actor.HasItem("gun"))
{
 Game.ChangeScene("scenes\OfficeHallway\OfficeHallway.scene");
}

else
{
  actor.TurnTo(DI_LEFT);
  actor.Talk("I can´t get out without my basic stuff.");
}

ciberspace

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 116
    • View Profile
    • Tele Juego
Re: Learning scripting == actor.hasitem(item)
« Reply #1 on: December 22, 2012, 09:18:04 AM »

Code: WME Script
  1. on "LeftClick"
  2.  
  3. {
  4.   actor.GoToObject(this);
  5.  
  6.  
  7. if (actor.HasItem("gun")==true)
  8. {
  9.    Game.ChangeScene("scenes\OfficeHallway\OfficeHallway.scene");
  10. }
  11.  
  12. else
  13. {
  14.   actor.TurnTo(DI_LEFT);
  15.   actor.Talk("I can´t get out without my basic stuff.");
  16. }
  17.  
  18. }

diegoquarantine

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 50
    • View Profile
    • Buenos Aires Quarantine Studio
Re: Learning scripting == actor.hasitem(item)
« Reply #2 on: December 22, 2012, 12:35:55 PM »


Hi, thanks!, I tested it but at first gave me a syntax error. I think it was because in your example you didn´t close the "on click" brackets. So I tried this:

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


on "LeftClick"

{
  actor.GoToObject(this);
 
if (actor.HasItem("gun")==true)
{
 Game.ChangeScene("scenes\OfficeHallway\OfficeHallway.scene");
}

else
{
  actor.TurnTo(DI_LEFT);
  actor.Talk("I can´t get out without my basic stuff.");
}
}


But still didn´t work, the character gives the "or else" state having the item or not.
This is the Item code so you can see that the name is ok.
Code: [Select]
ITEM
{
   CURSOR_COMBINED = TRUE
   CAPTION = "A gun"
   NAME = "gun"
   IMAGE = "items\gun_I.png"
   CURSOR = "items\gun_I.png"
   CURSOR_HOVER = "items\gun_h.png"
   SCRIPT = "items\gun.script"
}

Thanks!

lof

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 19
  • A Leap Of Fate
    • View Profile
Re: Learning scripting == actor.hasitem(item)
« Reply #3 on: December 22, 2012, 12:40:21 PM »

i think it depends on how you picked up the item
if you used, actor.TakeItem then your first code should work
but if you picked it using game.TakeItem, then you should check it like this


if (game.HasItem("gun"))
Logged

diegoquarantine

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 50
    • View Profile
    • Buenos Aires Quarantine Studio
Re: Learning scripting == actor.hasitem(item)
« Reply #4 on: December 22, 2012, 12:42:19 PM »


Ok, I made it work changing (actor.HasItem) for (Game.IsItemTaken), but still I think (actor.HasItem) should work, I don´t know why but seems like the default inventory is not storing items using the main actor object or something like that.

Thanks for the help!. The survivor guide to scripting is just what I was looking for.

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: Learning scripting == actor.hasitem(item)
« Reply #5 on: February 13, 2013, 03:30:15 PM »

Multiple inventories

In WME each object (game, actors, entities) can have its own private inventory. It's mainly useful for games with multiple main characters. In that case you can control whose inventory is currently displayed on screen. This is done by setting the Game.InventoryObject attribute. By default this attribute is set to the Game object, which is just fine for single-inventory games. If you have multiple switching actors you'll want to set this attribute to the current actor.

Logged
 

Page created in 0.039 seconds with 24 queries.