Oct 7, 2013

vJASS for mules #1: Types and variables

What is JASS?
JASS (Just Another Scripting Syntax) is the Warcraft 3's programming language. It's used to control the most of features in a map, so it's a wise idea to learn it if you intend to develop complex systems.

What is vJASS?
vJASS is a extension of JASS created by Veroxian. It was made to support some basic concepts of OOP (Object-Oriented Programming), but you don't need to worry about it now. The thing you need to bear in mind is that vJASS is more powerful than JASS. To run vJASS you need to install JNGP.

Value
It's anything that can be stored, i.e, the number 1, 2 or the word "banana".

Type
The values 1 and "banana" belong to different classifications. Each classification is called "type". There are several types, and you can create your own.

Main types (Also called primitives)
  • integer: It's the type that represents the integer numbers, i.e, 1, 2, 3...-8000.
  • real: It's the type that represents the rational numbers, i.e, 2.5, 3/4, ...-80.000001.
  • string: It's the type that represents the words, i.e, "ana", "banana", ..."apple". They need to be typed with quotation marks in order to be not confused with general code.
  • bool: This type owns only two values: true or false. It's used to create logical expressions.

Variables
Sometimes you want to store values to use them later. It's possible with variables. To create a variable, you need to inform the type, the name of variable and the value.

integer myVariable = 1

In this example, we are creating a variable of type integer and it's now storing the value 1.
A variable can only store values that belong to the type it was informed in its creation.

Variables are called so because we can change the value that they store, i.e., if now I want to assign the value 2 instead of 1 to myVariable, I follow the procedure:

set myVariable = 2

Important note: vJASS is case-sensitive. It means that "myVariable" and "MyVariable" are different variables!

Operators
We can perform operations with variables. See the example:

integer variable1 = 10
integer variable2 = 20
variable1 + variable2

It will yield 30. Of course the operands have to be compatibles. You can't subtract 1 from "ana". But you can add "ana" to "na", and it will yield "anana". See the list of the most of operations and their compatibilities:

Operator
Function
Compatibility
+
Adds two numbers or concatenates two words
Between numbers, between strings
-
Subtracts   two numbers
Between numbers
*
Multiplies two numbers or repeats a word ‘n’ times
Between numbers, Between strings and numbers
/
Divides   two numbers
Between numbers
==
Compares two variables and returns true if they’re equals or false otherwise
Any
Compares two variables and returns true if the first is greater than the second or false otherwise
Any
Compares two variables and returns true if the first is lesser than the second or false otherwise
Any
>=
Same to greater but including equal
Any
<=
Same to lesser but including equal
Any
or
Returns true if any of both variables is true, false otherwise
Between booleans
and
Returns true if both of variables are true, false otherwise
Between booleans
not
Returns true if a variable is false or false if true
Between booleans

Comments
Comments are pieces of text that are ignored by compiler. It's useful when you want to explain something about your code. To create comments, just write "//" in front of the text. Example:

// This is a valid comment

You can also create comments with several lines. You just need to write /* */ and between the quotes. the text. Example:

/*
This is a multi-line comment.
It's useful when your comment is too long
*/


Answer mentally:
  • What is a value?
  • What is a type?
  • Which type is the value "1"? And 1? What about '1'?
  • What is a variable? Why is it important?
  • What are comments? How do I create one? 


<<Previous>>                                                                                  <<Next>>

No comments :

Post a Comment