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: Custom actor variables  (Read 3593 times)

0 Members and 1 Guest are viewing this topic.

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Custom actor variables
« on: February 26, 2011, 07:08:16 PM »

I have my actors and want to set some custom variables, which I can access using actor_name.customVariable. Those variables will be set in the beginning of each chapter.

First question is how to set such variables? If I set them in the actor_name.script should they be global or simple var? Second question is when to initialize them? I know if I initialize them for instance in the actor_name.script, they will be reset every time I Game.LoadActor3d() to load the actor. Is this true?
Logged

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Custom actor variables
« Reply #1 on: February 26, 2011, 09:29:43 PM »

- deleted misinformation - :)  ::rock ::rock ::rock
« Last Edit: February 27, 2011, 05:53:55 PM by Spellbreaker »
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: Custom actor variables
« Reply #2 on: February 26, 2011, 11:45:37 PM »

nonsense,

Code: WME Script
  1.  
  2. actor.AnyVariable = "test";
  3. Game.Msg(actor.AnyVariable);
  4.  
  5.  

simple as that.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom actor variables
« Reply #3 on: February 27, 2011, 12:12:56 PM »

And if you're setting them directly in the actor's script, you can use

Code: WME Script
  1. this.AnyVariable = "test";
  2.  

As for Game.LoadActor(), it creates an entirely new actor object, so no, the custom properties are not retained.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Custom actor variables
« Reply #4 on: February 27, 2011, 04:07:29 PM »

Thanks a lot guys for your quick answers.

So, if I define them in the actor's script like this:

Code: WME Script
  1. this.AnyVariable = "test";
  2.  

will the variable be reset every time I call Game.LoadActor()? I am a bit confused as to what parts of scripts are executed when. In the WME documentation (help and metamorphium's book) it is said that whenever you include a script, the variables that are set as

Code: WME Script
  1. var variable = value

inside that script (outside functions and event handlers) are reset to value with each include. So, if I have such code in lets say base.inc it will not work. If I have it inside game.script or game_loop.script, will they be reset every time the game is run, even if the user loads a saved game?

Thanks again.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom actor variables
« Reply #5 on: February 28, 2011, 12:05:26 PM »

Scripts in WME are always owned by some game object. So when the object is instantiated, its scripts are started, and when the object is deleted, its scripts are terminated. Using Game.LoadActor() creates a new actor object (which in turn starts its scripts). When you delete the actor, its scripts are deleted as well.

Local variables (declared with "var") are part of the running script. When the script is terminated, its local variables cease to exist.
Global variables (declared with "global") exist all the time, they are not dependent on any scripts (the scripts only use existing global variables or create new ones).
Custom object properties (set with this.SomePropery or actor.SomeProperty) are owned by their parent object. When the object is deleted, so are its custom properties.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Custom actor variables
« Reply #6 on: March 01, 2011, 03:36:34 PM »

What about includes? In the WME Book, in chapter 2.5 it says:

Quote
Important:
Never initialize your variables in the include files. They will get reinitialized with every inclusion of your script.

So if I have a script.inc file which contains:

Code: WME Script
  1. var variable = 10;
  2.  

and include this script in two scripts attached to 2 entities in a scene. Does this mean that the code will be executed twice, one for each include, each time the scene is loaded?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Custom actor variables
« Reply #7 on: March 01, 2011, 05:30:09 PM »

Does this mean that the code will be executed twice, one for each include, each time the scene is loaded?

Yes. Include files work just as an automated copy&paste feature. The content of the include file is literally inserted into the script.

The reason why meta warns about this is that some people in good faith put something like:

Code: [Select]
global myWindow = Game.LoadWindow("some.window");

to the base.inc include file. Now, since base.inc is by default inserted to every single script, their game kept loading a new window every time some script was executed, resulting in huge memory leak and extremely long loading/saving times.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Custom actor variables
« Reply #8 on: March 02, 2011, 12:24:20 PM »

Thank you it is quite clear now.
Logged
 

Page created in 0.12 seconds with 24 queries.