DNM Script for beginners
From kwiki
In construction
Please let me know (http://www.konradp.com/contact.htm) that I forgot to write this article.
Comments
OK, let's start with comments. Not because it's so important, but you will see them in most of the scripts. In DNM Script just like in many other programming languages (e.g. C++, JavaScript) you can add comments like this:
//This is a comment. Two // means that this line will not be interpreted/executed.
//This is another line. Now let's see some code:
MessageBox("Hello world!");
//the above line will be executed. Now code again:
MessageBox("Hello again");//You can add comments like this too
/*
Comment again. Everything between
/* and */ is a comment too.
It can spread along many lines.
*/
Functions
Have you noticed this "MessageBox.. something"? It's a function. Let's now look at it more closer:
MessageBox("Hello");
"MessageBox" is a function. "Hello" is an argument. This function simply displays a message box with given text. As you can see, in DNM Scripts, just like in most of the programming languages, you give arguments in parentheses: (). Additionally, we use "", to tell the compiler, that this is a text (not a number or other stuff). Let's look at another simple function called "sin" - as you may guess, it returns a sinus of given number:
sin (4);
This time we called a function "sin" with one argument - 4 which is a number (we don't enclose numbers in "", we only do it with text strings). This function returns a result of "sinus of (4)", but when you'll try this script you won't see anything. Why? Because we want to do something with this result. Let's see... maybe we could display it?
You already know the "MessageBox" function ? It takes one argument. We used a text string "Hello", but here's the news: you can also use a result of a function:
MessageBox(sin (4));
Do you get it? In plain English it means: hey compiler, show a Message Box with sinus of 4. The compiler will first execute the function "sin" then will execute "MessageBox" with the result. So - you can pass not only strings, but also results of other functions. Let's look at another example:
pow (4,2);
Two numbers? Yes - because this function takes two arguments - "pow (x,y)" - returning x raised to the power y. As you can see, you separate them by a colon (,).
Now it's time for a test. How will look a code which displays a result of: 2 raised to sinus of 10?
Think first.
Now look at the answer:
MessageBox(pow(2,sin(10)));
So many parentheses... It's because there are two functions nested in another function. First the complier will calculate "sin(10)", it will pass the result to the "pow" function which will calculate 2 raised to the result of sin (10). Finally, "MessageBox" will display the result.
Variables
To be continued...
