The Dink Network

no for loop and != in dink c?

May 6th 2011, 06:35 AM
duckdie.gif
welovefudge
Peasant He/Him Russia
I hope life isn’t a joke, because I don’t get it. 
is the statement if(&a!=0) and for loops permitted in dink c?
what about the else statement?
May 6th 2011, 07:02 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Read the chapter about "Control Structures" of dinkc.chm.

All usual comparison operators are allowed, just a couple of notes. We also have else-statements.

There must be a space after "if".
There must be spaces around the comparison operator.
Function calls inside the condition are not really allowed. It works for some functions (like "get_sprite_with_this_brain()"), and doesn't for others. I always use a temporary variable.
I have no clue if it accepts 0 and 1 as false/true. I always just use "== 0" and "== 1" and such.
Put "if (condition)" on its own line. Also put "{" and "}" on their own lines.
Put "else" on its own line. Also put "{" and "}" on their own lines.

The only kind of loop you have to make yourself with a combination of goto and if-statements. In short, things can look like this:

void main( void )
{
  int &count = 5;
}

void talk( void )
{
  freeze(1);
  loop:
  if (&count != 0)
  {
    say_stop("`%&count bottles of beer!", &current_sprite);
    &count -= 1;
    goto loop;
  }
  else
  {
    say_stop("`%Strictly, this else is not needed, but for demonstration purposes...", &current_sprite);
    say_stop("Okay, now you're really not making sense...",1);
  }
  unfreeze(1);
}
May 6th 2011, 10:48 AM
dinkdead.gif
"I have no clue if it accepts 0 and 1 as false/true. I always just use "== 0" and "== 1" and such."

You can do
if (&var)

which is exactly the same as
if (&var != 0)

If that's what you meant?

However I don't think you can do
if (!&var)