The Interpreter, Subroutine and Value Objects

Posted by Wednesday, July 13, 2016 11:23:00 PM Categories: basics c# Easy Freedom Script Windows

The Trio of Freedom script

Rate this Content 1 Votes

The Interpreter, Subroutine and Value Objects

 

The Interpreter, Subroutine and Value Objects are the building blocks of Freedom Script (FS). This trio is simple to use. The key to effective FS usage is understanding how to set them up. Let us dive in.

The Interpreter object is the workhorse of FS.  It loads external scripts and runs them. Simply enough it has a load and run function. Basically you attach a Unity C# script to a gameobject.  Then create the Interpreter object in the script. You can use an empty gameobject such as one you may create as a gamemanager for a level or one attached to an in game entity such as a tank or space alien.  The setup is the same. Each Interpreter object you create will create a separate script instance. But you can share custom language elements between each instance. We will get to that soon enough. Though the interpreters object you can run the FS script all at once or step by step. Each technique has its place. A good example is if you are running the script from the AWAKE function possibly for a level setup or from an update function.   Let’s try not to get ahead of ourselves.

The Subroutine object is the connector or bridge from unity to your external FS script files. In theory you don’t have to ever use this object but your scripts would never be able to talk to unity. Your FS scripts would be doomed to computing numbers and strings in its own little universe.  They could never interact with in game elements.  I hope that’s not what we want. The Subroutine object is how you extend or define your custom language. This is where the real power of FS shines.  The subroutine object or more precise the class you will derive from the subroutine object is the c# code you want unity to run. The code can access FS variables (read or write) or any functions or data the gameobject it is attached has access to.  Most MonoBehavior methods and data are exposed.  This is where you extend the basic FS language and gives you endless possibilities and freedom to create your own language!

You will create a class based on the Subroutine object and “register “ it with the interpreter object. As the interpreter object is running your FS script and it encounters the function name you chose to represent this block of code it will execute it. The C# code inside the subroutine class will run. Here is where can you change FS script variables and return the processed data back to the FS script or issue a unity command. You could move an object’s transform or preform a raycast and return the result to the FS script. In this object is where the work gets done and then communicates it back to the FS script. It sounds more complicated than it really is. Once you work with the object you will fall in love with it. (well..ok maybe that’s a bit much)

The last part of the trio is the Value object.  It is the holder of information for your FS scripts. You can create these in your unity c# script and exchange or pass them to your FS script. These objects are the representation of the data on the Unity side. On the FS script side they are just data that can be stored in variables or used in expression.  They are simple C# objects and wrap actual values. They have some built in functions that make working with them easy.  Just remember data inside your FS script is stored as value objects “under the hood” on the Unity side but when the FS script views the data it behaves and you interact with it as if it was just plain old data with no wrapper. All data in Value objects are stored as text strings. In FS scripts, their value is converted based on the context they are used. In your C# code you would convert the string to a number.  Again this sounds complex when you explain it but in practice it is very natural and simple. FS supports strings, integers and floats.   

  

Well that’s it ! Just three simple objects will unlock the world of scripting. It will give you the freedom to create a custom language. True Freedom!

2016

Site Map | Printable View | © 2008 - 2020 GoodCarma.net | GoodCarma.net | Community Tools since 2008 | SmithTown New York