Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Accessing an Object's Member Variable  (Read 2649 times)

0 Members and 1 Guest are viewing this topic.

greg

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Accessing an Object's Member Variable
« on: January 06, 2007, 01:03:28 AM »

Hi All,

How can I access an object's member variable from a non-member function?

Within the game daemon script, I'm trying to access a member variable of the active object:

== my_object.script ==

...
var myState = "foo";
...

== game_daemon.script ==

...
var active_object = Game.GetActiveObject();
var active_object_state = active_object.myState;
Game.Msg(active_object_state); // this prints [null]
...

So far, the only way I can get this to work is by creating a GetMyState() method in my_object.script that returns myState and then calling active_object.GetMyState() from game_daemon.script.

Do I need to write a wrapper method for every variable I need to access from a non-member function?  If so, is there a way to put the method in a script attached to the object (via this.AttachScript()), so that I don't need to copy the wrapper methods into every instance of the object?  (In my testing, calling Game.Msg(this.myState) from the attached script also displays [null].)

Thanks,
Greg
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: Accessing an Object's Member Variable
« Reply #1 on: January 06, 2007, 02:10:30 AM »

correct way to do this is:

== my_object.script ==

...
this.myState = "foo"; // note that since it's a member declaration you don't precede it with var.
...


Hope this helps.
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.016 seconds with 23 queries.