Author Topic: add_action() simple? lol!  (Read 3162 times)

vakuta

  • Guest
add_action() simple? lol!
« on: October 01, 2006, 03:34:52 pm »

Is add_action() as simple as it is supposed to be?  Maybe so, maybe not.  Either way, some of this code looks wierd to me, so, here is the **simple** example add_action() that changes a desc.  Heck, I tried to use it as a template to create my own and wound up with a gallon of errors, so, here goes:



 



 





#include <lib.h>

#include <rooms.h>

#include "ex.h"



//  The #include "ex.h" is used in each of these files to remember

//    the defines for EXPATH and other variables we have defined

//    that all of these files use.  It would be tedious to have to

//    put the #define EXPATH in every file, so we put it into one

//    and include it as a reference for each file that needs it.

//    Consider it a library card.  The books that are in the library

//    (the #define's) are referenced every time you see EXPATH.



inherit LIB_ROOM;



//   I'm defining a global variable here called once to be used later

//     in the file.  A global variable is something that can be used

//      by any function in this room.  There are also local variables

//     that can be defined only in the variable using it.



int once;



//   I'm also defing a function lever_pulled() that will be called later.

mixed lever_pulled();



void create()

{

    ::create();

    SetAmbientLight(30);

    SetShort( "Lever Pull" );

    SetLong("This is an example room for a simple add_action which changes "+

      "a description.  There's a lever to pull."

    );



   SetExits( ([

   "north" : EXPATH + "exroom2",

   "south" : EXPATH + "entrance",

      ]));



   //   Here, take a look at how I set the lever item.  It is different

    //     that you saw in the entrance room.  What I am doing here is

    //     calling a functional.  When the player types 'look lever', it

    //     will call the functional (: lever_pulled :) that we defined above.

    //     I'll explain later in this file.



   SetItems( ([

   "lever" : ((: lever_pulled :))

      ]) );



}



//  In the init() function, I am setting our global variable 'once' to 0.  This

//    is used to reset the lever back when the room resets or the mud reboots.

//    so the next player who comes in to pull the lever, they can.

//    In the init() function, we also define the actions that can be done in the

//    room.  In this case, we need a pull action to 'pull lever'.  Whenever a player

//    types pull, it will call the function aa_pull().



void init()

{

    ::init();

    add_action("aa_pull","pull");

    once = 0;

}



//   This is the function that is called when a player types pull as mentioned above.

//      First, we need to check and see if they are pulling the correct thing.  the

//      string str is defining a local variable that will be used in this function.

//      Next, we have if( str != "lever").  That is saying if I type 'pull finger',

//      it will write 'Pull what?'.  The \n symbol means a carriage return or 'enter'

//      to go to the next line.



mixed aa_pull(string str)

{

    if ( str != "lever")

    {

   write( "Pull what?\n" );

   return 1;

    }



   //   Here we are going to check if the lever has been pulled.  If it has,

    //     it's going to tell the player that and exit the aa_pull() function.

    //     this is done by the return 1; that you see here.



   if( once ==1 )

    {

   write( "The lever's already pulled." );

   return 1;

    }



   //  If the lever has not been pulled, this part starts.  As you'll notice, we

    //    set once = 1 to indicate that the lever has been pulled.



   write("You pull the lever!\n");

    say(this_player()->GetName() + " pulls the lever!\n");

    once=1;

    return 1;

}



//   I told you I'd explain what the functional (: lever_pulled :) was for.

//     Below, it checks to see if the lever has been pulled.  if( !once )

//     says, if once is equal to 0 (not pulled) it returns and says the lever

//     has not been pulled.  If once is not equal to 0, then it means that it

//     has been pulled and returns a different message.



mixed lever_pulled()

{

    if( !once )

   return "The lever is pushed into the wall.  Perhaps you could pull it.";

    return "The lever has already been pulled.  You're too late!";

}



 





And bye the way, I had to indent it myself with the indent command.   :P


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
add_action() simple? lol!
« Reply #1 on: October 01, 2006, 03:39:09 pm »

Zaroth,



You'll need to explain what it is that is confusing you here.



If what you're asking for is help with your code that doesn't

work, please post that.



vakuta

  • Guest
add_action() simple? lol!
« Reply #2 on: October 01, 2006, 03:50:30 pm »

Oh, some of the punctuation, why my code won't work that I used as a template... here, I'll post my code:



#include <lib.h>



inherit LIB_ROOM;



int once;



mixed button_pushed();



static void create() {

   room::create();

   SetClimate("outdoors");

   SetAmbientLight(50);

   SetShort("The waterslide");

   SetLong("This little waterslide is where bastards go for being naughty.  Your only hope is to push the button.");

   SetItems(([  "button"  : ((: button_pushed :))

      ]));


   

}





void init()

{





   ::init();

   add_action("aa_push","push");

   once=0;



}





mixed aa_push(string str)



{



  if( str !="button")

{



 write("What, the button?");

  return 1;



}





if(once ==1) {





write("Doh, some other naughty bastard musta been here!\n");

return 1;



}



 



write("You push the button and the floor falls out.\n");

say(this_player()->GetName() + " pushes the button and the floor promptly falls out.\n");

once=1;

return 1;



}





mixed lever_pulled()

{





    if( !once ) {

        return "The big, red button is on a console.  A notice is over it, saying, "PUSH IT, BASTARD!";

        return "The big red button has been pushed.  The floor is gone, revealing a huge waterslide, and the whole panel



around the button is burnt and fried.";



}


vakuta

  • Guest
add_action() simple? lol!
« Reply #3 on: October 01, 2006, 03:53:48 pm »

And here is the error I get when I try to goto the room that code should create:





 /realms/zaroth/slide.c line 68: syntax error


   

/realms/zaroth/slide.c line 69: Illegal character (hex 2e) '.'


   

/realms/zaroth/slide.c line 69: Illegal character (hex 2e) '.'


   

/realms/zaroth/slide.c line 77: End of file in string


   

---

*Error in loading object '/realms/zaroth/slide'

Object: /secure/save/creators/z/zaroth (/lib/props/move.c) at line 31



'<function>' at /secure/save/creators/z/zaroth (<function>) at /:0

'cmdAll' at /secure/save/creators/z/zaroth (/lib/command.c) at line 93

'cmd' at /cmds/creators/goto at line 37

'eventMoveLiving' at /secure/save/creators/z/zaroth (/lib/player.c) at line 245

'eventMove' at /secure/save/creators/z/zaroth (/lib/player.c) at line 225

'eventMove' at /secure/save/creators/z/zaroth (/lib/interactive.c) at line 464

'eventMove' at /secure/save/creators/z/zaroth (/lib/props/move.c) at line 31

'CATCH' at /secure/save/creators/z/zaroth (/lib/props/move.c) at line 31

Trace written to /log/catch

*Error in loading object '/realms/zaroth/slide'



You remain where you are.


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
add_action() simple? lol!
« Reply #4 on: October 01, 2006, 04:31:51 pm »
Here's a working copy of your code. Your difficulty had nothing to
do with add_action. You incorrectly used punctuation.  

-Crat




code:
#include <lib.h>

inherit LIB_ROOM;

int once;

mixed button_pushed();

static void create() {
    room::create();
    SetClimate("outdoors");
    SetAmbientLight(50);
    SetShort("The waterslide");
    SetLong("This little waterslide is where bastards go for being naughty. Your only hope is to push the button.");
    SetItems(([ "button" : ((: button_pushed :))
      ]));

}


void init()
{


    ::init();
    add_action("aa_push","push");
    once=0;

}


mixed aa_push(string str)

{

    if( str !="button")
    {

        write("What, the button?");
        return 1;

    }


    if(once ==1) {


        write("Doh, some other naughty bastard musta been here!\n");
        return 1;

    }



    write("You push the button and the floor falls out.\n");
    say(this_player()->GetName() + " pushes the button and the floor promptly falls out.\n");
    once=1;
    return 1;

}


mixed lever_pulled()
{


    if( !once ) {
        return "The big, red button is on a console. A notice is over it, saying, \"PUSH IT, BASTARD!\";
return "The big red button has been pushed. The floor is gone, revealing a huge waterslide, and the whole panel around the button is burnt and fried.";

}


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
add_action() simple? lol!
« Reply #5 on: October 01, 2006, 07:21:12 pm »
The follow code works:



slide.c



code:


#include <lib.h>

inherit LIB_ROOM;

int once;

mixed button_pushed();

static void create()
{
    room::create();
    SetClimate("outdoors");
    SetAmbientLight(50);
    SetShort("The waterslide");
    SetLong("This little waterslide is where bastards go for being naughty. Your only hope is to push the button.");
    SetItems(([ "button" : ((: button_pushed :))
      ]));
}


void init()
{
    ::init();
    add_action("aa_push","push");
    once=0;
}

mixed aa_push(string str)
{
    if( str !="button")
    {
        write("What, the button?");
        return 1;
    }

    if(once ==1) {
        write("Doh, some other naughty bastard musta been here!\n");
        return 1;
    }
    write("You push the button and the floor falls out.\n");
    say(this_player()->GetName() + " pushes the button and the floor promptly falls out.\n");
    once=1;
    return 1;
}

mixed lever_pulled()
{
    if( !once )
        {
        return "The big, red button is on a console. A notice is over it, saying, \"PUSH IT, BASTARD!\"";
return "The big red button has been pushed. The floor is gone, revealing a huge waterslide, and the whole panel around the button is burnt and fried.";

        }
}

vakuta

  • Guest
add_action() simple? lol!
« Reply #6 on: October 01, 2006, 07:23:08 pm »

Now look at this, I changed my code to look exactly like the lever pull add_action() example, except all the commentary in between the code.  Now somebody, please, tell me how these two code sets can look so alike, except the names of functions, and not work!!  First, my slide code, with some of Cratylus's additions:





#include <lib.h>



inherit LIB_ROOM;



int once;



mixed button_pushed();



static void create() {

    room::create();

    SetClimate("outdoors");

    SetAmbientLight(50);

    SetShort("The waterslide");

    SetLong("This little waterslide is where bastards go for being naughty. Your only hope is to push the button.");

    SetItems(([ "button" : ((: button_pushed :))

      ]));



}





void init()

{





    ::init();

    add_action("aa_push","push");

    once = 0;



}





mixed aa_push(string str)

{



   if( str !="button")

    {



       write("What, the button?\n");

        return 1;



   }





    if( once ==1 ) {





        write("Doh, some other naughty bastard musta been here!\n");

        return 1;



   }



 





    write("You push the button and the floor falls out.\n");

    say(this_player()->GetName() + " pushes the button and the floor promptly falls out.\n");

    once=1;

    return 1;



}





mixed button_pushed()

{





    if( !once ) {

        return "The big, red button is on a console. A notice is over it, saying, \"PUSH IT, BASTARD!\";

return "The big red button has been pushed. The floor is gone, revealing a huge waterslide, and the whole panel around the button is burnt and fried.";



}



 



 



And now the example code:





#include <lib.h>

#include <rooms.h>

#include "ex.h"



//  The #include "ex.h" is used in each of these files to remember

//    the defines for EXPATH and other variables we have defined

//    that all of these files use.  It would be tedious to have to

//    put the #define EXPATH in every file, so we put it into one

//    and include it as a reference for each file that needs it.

//    Consider it a library card.  The books that are in the library

//    (the #define's) are referenced every time you see EXPATH.



inherit LIB_ROOM;



//   I'm defining a global variable here called once to be used later

//     in the file.  A global variable is something that can be used

//      by any function in this room.  There are also local variables

//     that can be defined only in the variable using it.



int once;



//   I'm also defing a function lever_pulled() that will be called later.

mixed lever_pulled();



void create()

{

    ::create();

    SetAmbientLight(30);

    SetShort( "Lever Pull" );

    SetLong("This is an example room for a simple add_action which changes "+

      "a description.  There's a lever to pull."

    );



   SetExits( ([

   "north" : EXPATH + "exroom2",

   "south" : EXPATH + "entrance",

      ]));



   //   Here, take a look at how I set the lever item.  It is different

    //     that you saw in the entrance room.  What I am doing here is

    //     calling a functional.  When the player types 'look lever', it

    //     will call the functional (: lever_pulled :) that we defined above.

    //     I'll explain later in this file.



   SetItems( ([

   "lever" : ((: lever_pulled :))

      ]) );



}



//  In the init() function, I am setting our global variable 'once' to 0.  This

//    is used to reset the lever back when the room resets or the mud reboots.

//    so the next player who comes in to pull the lever, they can.

//    In the init() function, we also define the actions that can be done in the

//    room.  In this case, we need a pull action to 'pull lever'.  Whenever a player

//    types pull, it will call the function aa_pull().



void init()

{

    ::init();

    add_action("aa_pull","pull");

    once = 0;

}



//   This is the function that is called when a player types pull as mentioned above.

//      First, we need to check and see if they are pulling the correct thing.  the

//      string str is defining a local variable that will be used in this function.

//      Next, we have if( str != "lever").  That is saying if I type 'pull finger',

//      it will write 'Pull what?'.  The \n symbol means a carriage return or 'enter'

//      to go to the next line.



mixed aa_pull(string str)

{

    if ( str != "lever")

    {

   write( "Pull what?\n" );

   return 1;

    }



   //   Here we are going to check if the lever has been pulled.  If it has,

    //     it's going to tell the player that and exit the aa_pull() function.

    //     this is done by the return 1; that you see here.



   if( once ==1 )

    {

   write( "The lever's already pulled." );

   return 1;

    }



   //  If the lever has not been pulled, this part starts.  As you'll notice, we

    //    set once = 1 to indicate that the lever has been pulled.



   write("You pull the lever!\n");

    say(this_player()->GetName() + " pulls the lever!\n");

    once=1;

    return 1;

}



//   I told you I'd explain what the functional (: lever_pulled :) was for.

//     Below, it checks to see if the lever has been pulled.  if( !once )

//     says, if once is equal to 0 (not pulled) it returns and says the lever

//     has not been pulled.  If once is not equal to 0, then it means that it

//     has been pulled and returns a different message.



mixed lever_pulled()

{

    if( !once )

   return "The lever is pushed into the wall.  Perhaps you could pull it.";

    return "The lever has already been pulled.  You're too late!";

}



 





Now someone tell me how they could look so alike and mine not work.


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
add_action() simple? lol!
« Reply #7 on: October 01, 2006, 07:27:47 pm »
As I said on DS your code is missing an end bracket and an ".