The Dink Network

New Article : DinkC Tutorials : Lesson 1

I thought it was a good idea to create a series of tutorials to assist people in learning DinkC, so I took it upon me to do so. Redink1 thought about doing it too some time ago but never got around to it.

I know that there are already some tutorials that cover this subject, but from here on I will expand throughout the coming weeks. I don't know if this will be a weekly article, because I have to be in the right mood to write a tutorial. It may take only a day or maybe a little longer than a week, who knows.

For those of you who wanted to learn the language this will be a great opportunity and for those who already know it, well, they can refresh their knowledge. The tutorial is in the comments, so what are you waiting for?



DinkC Tutorial Lesson 1 :



Hello readers, this is the very first edition of the DinkC tutorials. They will cover everything from the basics to the grandmaster scripting tricks. For now, we’ll start with the easy stuff : writing a simple conversation between Dink and a tree.

1) Getting Started

First we’ll need to create the tree in (Win)DinkEdit. Once that has been done, attach the script "tree" to it. Exit the program and create the file tree.c.

2) Procedures

In DinkC there are several procedures that work as triggers for things to happen. For example :

- Void Main (void) is run from the moment the sprite appears on screen.

- Void Talk (void) is run when you talk to a sprite with spacebar.

- Void Push (void) is run when you try to push a sprite.

- Void Touch (void) is run when you touch a sprite’s hardbox.

- Void Hit (void) is run when you hit a sprite.

These are certainly the most common procedures, but there are more. We’ll talk about the more advanced procedures in later lessons.

Procedures are always built up in the following way:

Void Main (Void)

{

Stuff that happens comes here.

}


You define the procedure’s body by placing the "{" and "}" symbols.

3) Scripting the dialogue

To have a sprite say something we use say(), say_stop() or say_stop_xy(). All three will be discussed and used in our example.

- Say() is used to have a sprite say something without putting the script on hold.

- Say_stop() does the same as say() but puts the script on hold for a few seconds or until the player skips the current dialogue line.

- Say_stop_xy() is used to display text at specific x and y coordinates and also puts the script on hold.

*Note : You can only place 256 characters of text in one say() line. If you need to have the same sprite say a lot of text, split it up into multiple say() lines or the game will crash.

Onto our example. We want the tree to greet Dink, initiate a small dialogue that makes them both laugh at the same time and add an author’s comment in the end. There will be some new things in this example, but we’ll go over it step by step. For now, take a quick look at the following script :

Void Talk (void)

{

freeze(1);

say_stop("`6Hello there Dink, long time no see.", &current_sprite);

say_stop("Hi! Yeah, the valley of the talking trees just isn't on my route anymore.", 1);

say_stop("`6What a lame excuse, you've been neglecting us!", &current_sprite);

say_stop("Me? Not at all. It's those dang authors' fault!", 1);

say("`6Hahaha!", &current_sprite);

say("Hahaha!", 1);

wait(1000);

say_stop_xy("`%Remember, we're the ones that keep you alive!", 200, 300);

unfreeze(1);

}


That’s quite a bunch of new syntax in there. As promised, we’ll go through it step by step.

The first thing we notice is the freeze() command. This is used to keep a sprite from moving. Placing "1" between the brackets makes Dink freeze. The number one is always used to indicate Dink. We’re not freezing the tree since he’s not a moving sprite anyway. If you wanted Dink to talk to a moving sprite, you’d add freeze(&current_sprite). &current_sprite refers to the sprite to which the script is attached.

Next we come to the actual dialogue. We use say_stop() at first, because we don’t want the next line to show up at the same time. "`6" is the color code and determines the text color. Here’s a small table with the colors you can use and their color code :

1 : Pink4 : Orange7 : Light Grey # : Pink
2 : Dark Green5 : Purple8 : Dark Grey$ : Yellow (default)
3 : Light Blue6 : Brown9 : Light Blue% : White
Don’t forget to place the "`" in front of the color code. If you don’t use a color code, the default yellow will be used. That’s why when Dink says something the color code is left away.

Now we want Dink and the tree to laugh together for 1 second. So, we use say() for the laughing and wait(1000) to pause the script for 1000 milliseconds.

Then, the author interferes and his line is displayed on x-coordinate 200 and y-coordinate 300. There are some anomalies when using say_stop_xy() though, where the inputted coordinates don’t always match what happens on screen. You’ll have to experiment with this a little.

Finally, we unfreeze() Dink so he can continue his journeys.

Almost every line in DinkC ends with a ";". If you forget this, the line will be skipped or the script may not operate at all. There are some exceptions to this though. Procedures don't have them behind their name, nor do the "{" and "}" symbols.

That concludes the first lesson. Next time we’ll learn about variables and calculations. I hope you understand everything so far. If not, you can always send me an e-mail for help or ask about it on the board. See you next time.