In pyke, just like in python, you can create variables by just using the assignment operator:
name = 'string'
number = 23
a_list = [1, 2, "asdf"]
And... as you might expect, you can use same types you are allowed to use in python (integers, floats, strings, lists, dicts, ...)
Variables in pyke work almost the same as in python, but there is a subtle but important difference:
Python variables are visible only in the *pyke* file where they are defined.
Why? Because when you work on big projects, you don’t want to end up with a mess of global variables, you want to have control over which variables are shared and where, and, at the same time, you might want to be able to easily create as many local variables to a pyke file as you want.
So local variables have no mistery at all, you just assign a value to an identifier, and that’s it.
Usually you will use global variables to share the paths to the objects, libraries, binaries or any other kind of artifact you have created, on different pyke build files. In fact, if you think about it, you will soon realize that what you usually want to share between build files are dependencies, libraries or tools you have built previously.
To make this as easier as possible, and to avoid poluting the global namespace, a global object named ‘g’ has been created. ‘g’ works like a dictionary, but using dot notation, like referencing an attribute. ‘g’ is visible to all pyke files that are included anywhere in your project.
Let’s see how to share the variable ‘gold’ between different build files:
g.gold = "this is global string"
and then, to use it inside the same build file or other build file, you will just do:
print g.gold
That’s it.
Note
There is an exception to everything that has been said in this section, and that exception is that all ‘local’ variables created in the master.pyke file will be globally available on the other build files.