Storing Global Variables

From TDN

Contents

Original Question:

I'm not familiar with TGE at all, but I can code a bit. So, my questions with T2D are probably really, really basic stuff for people coming over from TGE. Two that I'm coming up with right away are:

1) Where do I store any kind of global variables or data? Things like playerMaxVelocity, playerHP, playerLives, etc? I'm assuming I instantiate a datablock, but the T2D references only describe T2D specific datablocks.

Along these lines, are all variables scoped inside of datablocks? Which are basically like structs? (Sorry I'm kind of a noob coder). Can I declare local variables inside of functions? Is it basically like C/C++ as far as control structures, etc? I guess this is a big huge topic... any help is appreciated though.

2) Are there any references for other useful commands, such as writing to the console for debugging. Anything like "printf" type parsing so I can check variables? Even better would be text on the screen. (There may be reference for this... haven't looked for that yet).

Answer:

  $playerHP = 10000; 
  
  echo($playerHP); 

Another Answer:

Here's the official GG Documentation to look through.

Another useful reference is...

Language Reference

Other than that Phil, just ask, we're always here, time-zones allowing. :)

Good Luck.

- Melv.

Another Answer:


  $playerInfo = new ScriptObject();
  $playerInfo.hp = 100;
  $playerInfo.lives = 10;

etc.....

You can also then do:


  $playerInfo.dump();

in the console and it will dump all the contents of the object...


Writing to the console for debuging:


  echo("debug info");

=)

Another Answer:

To answer some of your specific questions:

--Global variables are automatically placed in a namespace that is visible to other modules. It is as simple as using the $ in the front of the variable--that's what makes it global, and the script console takes care of the rest.

--Local variables are created dynamically as well (simply use them), and are indicated by the % in the front of the variable. These act pretty much just like local variables in other languages, and are only accessable via the same scope/namespace.

Another Question (self answered):

This is somewhat related, so instead of a new thread I figured I´d ask it here.

Is there a way to dynamically select a namespace? For instance:


  $myPref::::someVariable = "X";


Where is itself a variable. I´m trying to break user preference settings into groups by user name. Is this possible?

Edit: While I'm guessing that this isn't possible, if it is I'd love to know. :) But meanwhile, I've chosen to just do this:


  $myPref::someVariable[] = "X";


since it does essentially the same thing.