Set state on object
FireLite

Hi, is it possible to set a state on an object, i.e. click and pick up a key and later use it to open a door?

I'm trying to build an old school point'n click adventure. I just started with Wade and would appreciate it if someone could point me in the right direction.

/FireLite

 

All 2 Comments
Gio

Hi

If I understand your question correctly, yes absolutely. Wade just uses JavaScript, and in JavaScript you can add any property to any object,

You could do this in several different ways, it mainly depends on where you want to store your state. In your particular case, I'd do it this way: upon picking up the key (in the key's onClick function), store the state in the wade.app object so it's always available across different scenes:

wade.app.gotKey = true;

Then in the door's onClick function:
 

if (!wade.app.gotKey)
{
    return;
}

In an adventure game you may want to have an inventory rather than storing the state of each object, so you'd set up an empty object when starting the game:

wade.app.inventory = {};

Then you'd store items in there as you pick them up:

wade.app.inventory.key = true;

 

FireLite

Great, thanks for your feedback Gio, I will try this out.

/FireLite

Post a reply
Add Attachment
Submit Reply
Login to Reply