Overview and Script Definition

Posted by Wednesday, July 13, 2016 7:42:00 PM Categories: basics c# Easy Freedom Script Unity Windows
Rate this Content 2 Votes

Welcome to Freedom Script

What is Freedom Script ?

  • Freedom Script (FS) is language interpreter. It allows custom external language files, which you the game author or you the game player can execute and interact with objects within Unity.
  • These external language files (scripts) are plain text files and require nothing more than a text editor to create and change.
  • Because the language is interpreted and not complied these files can be loaded before or while the game is running.

What does Freedom Script do ?

  • FS provides the structure of a computing language then allows you the game developer to define and/or execute the FS language.
  •  The FS language can even be changed on the fly. This allows the scripts to expose different language elements to the script author dynamically
  • FS will take care of the heavy lifting, freeing you to focus on game development.

 

What language is FS based on?

  • FS uses basic common structure allowing you to just define “Game” functions
  • FS supported language structures
    • Global and local variables
    • User defined Functions that can return values
    • If then else decision structures
    • Looping structures such as
      • For next loops
      • While do loops
  • Common text handling and math functions

 

 

Let's start with FS built in language structures. This comes built into the language:

  • Script Definition  

  • The language is not case sensitive

  • An assignment also declares the variable global, if the variable didn't exist before and if it wasn't declared local within the same SUB.

    • Example would be name = "Bill" or age = 28
  • Values are typed (internally),but FS variables don't have a fixed type. They have the type of the value they're containing
    •  Possible types for values are int, double/real and string. All variables are internally stored as strings. If used in a "string context" an int or double is automatically converted to a string.  If used in an arithmetic context a string is automatically converted to a double (i.e. "12" + 3.5 yields 15.5)
    • simple statements are assignments: “varname = expression” or
    • calls: function name(expression1, expression2, ...)

 

  • Control flow structures
    • Decision branches  
      • IF expr THEN
      •         ...  statements ...
      •     ELSE
      •         ...  statements ...
      •     ENDIF
      • The ELSE part is optional, if there is no ELSE then the ENDIF appears directly after the THEN statements.

 

  • Looping
    • while loops
      •     WHILE expr DO
      •         ... statements ...
      •     ENDWHILE
      • for loops
        •     FOR var = start TO end DO
        •         ... statements ...
        •     ENDFOR

 

  • Special statements
    • RETURN expression -- return from a SUB
    • LOCAL var -- declares that a variable identifier refers to a local variable/visibility
    • Both special statements are only valid inside a SUB... ENDSUB

 

  • Operators:
    • The operators in expressions can be  +, -, *, /, div,mod, ^ and & for string concatenation.
    • There is  also a SUBSTR function for strings.
    • Other operators: =, <, <=, >, >=,  and, or, xor, not
  •  the last two  (xor an not) are only logical, no bitwise variants.   0 and  0.0 and "" are false values, every other value is true from a boolean point of view.

 

  • Operator precedence table (operators on same line – same precedence, lower lines in this text, lower precedence)
    • 0: unary -
    • 1: ^ (exponentiation operator)
    • 2: * / mod div
    • 3: + - & (& is for string concatenation)
    • 4: <= >= = < >
    • 5: not (logical)
    • 6: and (logical)
    • 7: or (logical)

 Of course, variables/SUBs can't use reserved words for names.

 

  • Automatic conversions:
    •  if in an arithmethic/relational operation there is a string
      • operand (and the other operand is numeric) that doesn't parse to a valid numeric value then its numeric value is considered 0
  • if both operands are strings in a relational operation then
    • the strings are compared as strings, not as numbers
    • if at least one of the operands is numeric they are compared as numbers

 

  • Primitive subroutines (build in):
  • error -- 0 arguments, just generates a RuntimeError (example for throwing an exception from a sub)
  • substr -- 3 arguments, a string, a starting position and alength - extracts a substring
  • len -- 1 argument, returns the length of the string or of the string representation of the numerical value passed as an argument

These are just regular Subroutines added to the interpreter. therefore "build in"

If the programmer doesn't use RETURN or LOCAL then the default
behaviour is to have only global variables + parameters.

 

Wow, you made it. If you are a programmer already  you should be familiar with this basic toolset. If you are new to programming do not feel overwhelmed. You most likely won’t need most of these commands. You can learn each function as you need it. I plan on posting many examples.

Google is your friend, these basic language structures are common to many languages. A few searches should provide you with many basic programming examples. As your skills grow rest assured Freedom Script will provide you with the platform to exercise your new knowledge.

 

Bill R.

 

 

2016

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