Non-saving global variables


  • Posts: 1243
Sometimes you need to transfer some data between scenes. That where Game Attributes come handy. But what's when you game use saving system and you don't want to save some things, like for example direction where player in rpg game is facing? Or current menu index in your RPG Menu (at start you want that arrow will point to first item, but on exiting menu and entering it it should point to last used option)?

I thought about it too. Many times. So I've came up with nice behavior with a bit too long name Non Saving global variables. Funny fact is that despite the fact this is Scene Behavior, you don't need to attach it to any scene to make it work.

Usage it's simple to save variable you need do this call in codemode block:
Code: [Select]
global__.vars.yourname = value;Notice two underscores after "global". Also "yourname" is global variable name of your choice. You don't have to worry about types too. It's automatically casted to/from Object type which can be anything. To retrieve it you may want to do this:
Code: [Select]
_someattribute = global__.vars.yourname;

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D


  • *
  • Posts: 384
Nice! I was just searching for something like that... :) Is this working with in iOS as well?

Is there the possibility that non saving global variables are included in Stencyl? Or better, a checkbox associated to every "game attribute", where you specify if this has to be saved or not.


  • *
  • Posts: 180

This working for v2? I cannot get it to work using code blocks in design mode.


  • Posts: 4
Don't work in Stencyl V2.

Trying to access unexistsing property of global__.
        global__.vars.playerX = actor.getX;


  • *
  • Posts: 6108
I think this will work in 2.x:
Create a Code Mode Scene behavior, set the Class Name to "global__".
Then add this line in the class body (right before "override public function init()"):
Code: [Select]
public static var vars:Object = new Object();