New code

Posted by Shadoan on Mon 30 Apr 2001 09:49 PM — 6 posts, 21,737 views.

Canada #0
Heya can anyone look at the code I just made, whenever I type selfdestruct it gives me Syntax: blabla but when i type selfdestruct ship now or the other option nothing happens. Here's the code:


void do_selfdestruct(CHAR_DATA *ch, char *argument)
{
    SHIP_DATA *ship;

{
  if ( (ship = ship_from_cockpit(ch->in_room->vnum)) == NULL )
  {
    send_to_char("&RYou must be in the cockpit of a ship to do that!\n\r",ch);
    return;
  }
          
  if ( !check_pilot( ch , ship ) )
  {
    send_to_char("This isn't your ship!\n\r" , ch );
    return;
  }
              
  if (ship->shipstate == SHIP_DOCKED)
  {
    send_to_char("&RYour ship is docked!\n\r",ch);    
    return;         
  }
                            
  if (ship->shipstate == SHIP_HYPERSPACE)      
  {
          
    send_to_char("&RYou can only do that in realspace!\n\r",ch);
    return;         
  }
    
  {
    if ( str_cmp( argument, "ship now" )
    &&   str_cmp( argument, "ship now silent" ) )
    
  send_to_char( "Syntax: 'ship now' or 'ship now silent'\n\r", ch );
  return;
    }
    
    if ( str_cmp( argument, "ship now" ) )
  
    send_to_char("Selfdestruct activated!",ch);
      echo_to_ship( AT_YELLOW , ship , "ALERT: Selfdestruct activated...you have one minute to get to minimum safe distance" );
        add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 );
    }
    
    if ( str_cmp( argument, "ship now silent" ) )
  
      send_to_char( "&RSilent selfdestruct mode activated...\n\r",ch ) ;
            add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 );
    }
        destroy_ship(ship , NULL);
}
Australia Forum Administrator #1
Your braces seem mismatched. For instance, I count 7 opening braces "{" but 8 closing braces "}".

Also, they seem placed in funny spots. For instance in the first four lines:


void do_selfdestruct(CHAR_DATA *ch, char *argument)
{
    SHIP_DATA *ship;
{  // <--- what does this one achieve?



I would closely look at your ifs and braces and make sure that you have them all where you want them.



Canada #2
I added that in because an error popping up and the brace seemed to stop it but now I removed it and it still is error-free...hrm strange. Can you tell me how to make a timer so that right after the ship hears the 'ALERT: blabla'
message a 60 second countdown starts and only AFTER 60 seconds it blows up? I already added a 60 seocnd timer in mud.h so i just need to know how to put in the selfdestruct code.
Australia Forum Administrator #3
Usually an error like that means there is an "if" with a mismatched brace, eg like this:



if (blah)
  do this
  do that
  }   // mismatched brace



Adding another brace somewhere else may make the error go away, but is probably in the wrong spot - ie. in this case the "if" won't behave as expected. You should really check that each brace belongs where it should.

As for how to make it self-destruct - I don't know that, maybe someone else does.

Amended on Tue 01 May 2001 11:47 PM by Nick Gammon
Canada #4
Sorry, I meant how to put IT(the timer) in the selfdestruct code, the SELFD in the destroy_ship function.
I tried rewriting the last part of the code to make the tiemrs work but to no success here's what I did:

do_selfdestruct(CHAR_DATA *ch, char *argument)
{
char arg[MAX_INPUT_LENGTH];
SHIP_DATA *ship;

blabla IFCHECKS blabla
...
if ( str_cmp( argument, "normal" )
&& str_cmp( argument, "silent" ) )
{
send_to_char( "Syntax: 'normal' or 'silent'\n\r", ch );
return;
}


if ( !str_cmp( arg, "normal" ) )
{
echo_to_ship( AT_YELLOW , ship , "ALERT: Selfdestruct activated...you have one minute to get to minimum safe distance" );
}
add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 );
ch->dest_buf = str_dup(arg);
return;

if ( !str_cmp( arg, "silent" ) )

add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 );
ch->dest_buf = str_dup(arg);
return;
{
destroy_ship(ship , NULL);
return;
}
}
Now it doesnt say the ALERT: thing and does nothing.
Thanks in advance because I'll forget to thank you later.

Australia Forum Administrator #5
It still seems to me that your braces are all over the place. You realise, I hope, that the extent of the IF is to affect between the opening brace and closing brace? Yours seem to not be done like that.

I would at least modify it like this, assuming that is what you are trying to do...


if ( !str_cmp( arg, "normal" ) ) 
  { 
  echo_to_ship( AT_YELLOW , ship , "ALERT: Selfdestruct activated...you have one minute to get to minimum safe distance" ); 
  add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 ); 
  ch->dest_buf = str_dup(arg); 
  return; 
} // <--- move this one here 

if ( !str_cmp( arg, "silent" ) ) 
{ // <--- move this one here 
  add_timer ( ch , TIMER_DO_FUN , 60 , do_selfdestruct , 1 ); 
  ch->dest_buf = str_dup(arg); 
  return; 
  destroy_ship(ship , NULL); 
  return; 
  } 
}