Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Variables - scene scope  (Read 3750 times)

0 Members and 1 Guest are viewing this topic.

HanaIndiana

  • WinterNewb
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 7
  • It's all about strategy and adventure!
    • View Profile
Variables - scene scope
« on: September 07, 2015, 11:40:58 PM »

Hopefully a quick question, in need of just a quick answer. I want to make sure I'm not moving forward doing things incorrectly.

I have a scene with many scripts. The scripts need to access a lot of the same variables. Once the scene is over, most of the variables won't be needed anymore.

Right now, in order for the scripts to access a lot of the same variables, I've set them up as Global (but not in base.inc).
It seems like this is the way to do it, right? And once the scene is over, I can set these to null, so they take up less memory.  I just want to make sure there isn't another (or better) way to share variables within the scope of a single scene.

Thanks!  ;D
Logged
hanagames.weebly.com

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Variables - scene scope
« Reply #1 on: September 08, 2015, 05:29:52 PM »

Yes global variables are the way to achieve this communication between your scripts. The default WME scene template creates a global variable you can use, which contains several variables which represent the scene state, e.g. in scene_init.script:

Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // scene state
  3. global Statenew_scene;
  4.  
  5. // default values
  6. if(Statenew_scene==null)
  7. {
  8.   Statenew_scene.Visited = false;
  9.   // add scene states here
  10. }
  11.  
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // setup scene according to state variables
  14. if(!Statenew_scene.Visited)
  15. {
  16.   Statenew_scene.Visited = true;
  17.   //do something
  18. }
  19.  

I would suggest that you group your global Scene variables this way so you don't get lost.

I am wondering though how many such variables you have in a scene and why do you need them? For instance if you have in a variable which represents whether a scene node is Interactive, you can query the node instead of checking the variable:

Code: WME Script
  1. var hotspot = Scene.GetNode(nodeName);
  2.  
  3. if(hotspot.Interactive){
  4. //do something
  5. }
  6.  

I am not sure how WME handles the memory. I don't know whether setting the variables to null will take up less memory.
Logged

HanaIndiana

  • WinterNewb
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 7
  • It's all about strategy and adventure!
    • View Profile
Re: Variables - scene scope
« Reply #2 on: September 08, 2015, 08:30:16 PM »

Thanks anarchist!

Basically, I have a scene with three "close-up" areas. One is the inside of a desk (setup as a layer), the inside of a photo album (setup as a layer), and his cellphone (setup as an interface I believe).

Each of these also contain entities the character can interact with. So the global variables I have are used to turn these layers/entities off and on. Making them Active when they need to be, and vice-versa.

You're right that I may not have to actually set them as variables. I'll have to check out my code later today.
Logged
hanagames.weebly.com

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Re: Variables - scene scope
« Reply #3 on: September 09, 2015, 01:42:10 PM »

my thought's

- don't think is so much an issue with memory, it's got more to do with programming style, having to plough you way through a whole load of globals which might be affected by this and that, is not something that aids bug fixing or program enhancement.

Much better to keep things discrete whenever you can
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Variables - scene scope
« Reply #4 on: September 09, 2015, 04:53:47 PM »

I agree with what eborr said. Initially it seems a good idea to have variables to check or control several things, but since you already have the information you need (e.g. whether the layer is Active etc) I believe it is better to query the layers instead of having to set the variables each time a layer becomes Active etc.

This is not from a memory point of view but from code organization point of view. You don't want too many global variables lying around, something that might happens as your game gets bigger. I usually use only the SceneState global variables mostly in case I want to change something on a scene when my actor does something in another scene.
Logged
 

Page created in 0.045 seconds with 24 queries.