The Dink Network

Reply to Re: Talking

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
May 8th 2005, 04:08 PM
goblinm.gif
Brackets separate a piece of code that you only want to run under certain circumstances.
Examples:

void main( void )
{
if (&story == 1)
{
//stuff inside these brackets is run if &story is 1
say("look, a tree", 1);
}
if (&love == 1)
{
//stuff inside these brackets is run if &love is 1
say("I am in love", &current_sprite);
}
}

This will make the sprite say "I am in love" if &love is 1 and make dink say "look, a tree" if &story is 1. These events are independent, each happens regardless of whether the other happens. Why are the brackets neccesary? Because there would be another way to parse these statements if there were no brackets. Observe:

void main( void )
{
if (&story == 1)
{
say("look, a tree", 1);
if (&love == 1)
{
say("I am in love", &current_sprite);
}
}
}

Now, dink will say "look, a tree" if &story is 1, and the sprite will say "I am in love" if &love is 1 AND &story is 1, because the second if statement will not be reached unless &story is 1.

If this is confusing, here are some rules.

1.For every open bracket, there is a closed bracket.

2.Procedures, like void main( void ) or main talk( void ) require brackets (don't ask me why ). For example, this is good:

void main( void )
{
say("this is where the stuff goes", 1);
}

But this is bad:

void main( void )
say("This doesn't go here!", 1);
{
}

And this is bad

void main( void )
{
void talk( void )
{
}
}

But this is good:
void main( void )
{
}
void talk( void )
{
}

3.If statements require brackets, for reasons already explained.