[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Aliases
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Aliases

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Neves   USA  (78 posts)  [Biography] bio
Date Fri 24 May 2002 04:34 AM (UTC)

Amended on Fri 24 May 2002 05:40 AM (UTC) by Nick Gammon

Message
I downloades the alias snippet from Samson's page (alsherok.net), and it works nicely, but I am trying to make it so that if a player makes an alias with a semicolon in it, it will interpret it as more then one command, and first execute the command before the semicolon then try doing the one after the semicolon. Here is what I've come up with so far, and it isn't working too well, if you have any suggestions how I can get it to work.


    char *x;
    char arg2[MAX_INPUT_LENGTH];
    int y;
    y = 0;
    x = arg;

    for( x = arg; *x != '\0'; x++ )
        {
      if(*x == ';')
      {
        y = 0;
        interpret(ch, arg2);
        strcpy(arg2, arg);
        arg2 == NULL;
        return TRUE;
      }
            else
            {
              arg2[y] = *x;
        y++;
      }
        }


This is only the code meant to look for a semicolon, but it doesn't seem to work properly. I'm not sure how clear I was, I can explain again if you can't understand what I want to do.

-Jay
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 24 May 2002 05:48 AM (UTC)
Message
For a start, you aren't terminating the new string with a null byte. Second, you are returning after finding a semicolon, which won't help. Third, the line "arg2 == NULL;" won't achieve much.

Try something like this:


char *x;
char arg2[MAX_INPUT_LENGTH];
int y;
y = 0;
x = arg;

for( x = arg; *x != '\0'; x++ )
  {
  if(*x == ';')
    {
    arg2[y] = 0;		// terminate arg2
    interpret(ch, arg2);  // interpret it
    y = 0;  // start at start of arg2 again
    }  // end of semicolon found
  else
    arg2[y++] = *x;  // copy it
  }  // end of for loop
  
// do final one after the semicolon

arg2[y] = 0;		// terminate arg2
if (arg2 [0] != '\0')   // if not empty
  interpret(ch, arg2);  // interpret it

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Neves   USA  (78 posts)  [Biography] bio
Date Reply #2 on Mon 27 May 2002 02:24 AM (UTC)

Amended on Mon 27 May 2002 03:37 AM (UTC) by Nick Gammon

Message
Thanks, but there was a slight error in it that I found for all those who want to use this code, change:


      if(*x == ';')
      {
        y = 0;
        interpret(ch, arg2);
        strcpy(arg2, arg);
        arg2 == NULL;
        return TRUE;
      }
            
to:

      if(*x == ';')
      {
        y = 0;
        if (arg2 [0] != '\0')   // if not empty
          interpret(ch, arg2);
        strcpy(arg2, arg);
        arg2 == NULL;
        return TRUE;
      }


In case a person puts two semicolons in a row this will make sure it doesn't turn up as a null char.

-Jay
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 27 May 2002 03:40 AM (UTC)
Message
I'm surprised it works with this:



strcpy(arg2, arg);
arg2 == NULL;


First, I don't think the strcpy will achieve much, and the line:


arg2 == NULL;


definitely won't, because that is just a test (== means "is equal to").

That line doesn't change anything, it just tests to see if arg2 is NULL, and throws away the result.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Neves   USA  (78 posts)  [Biography] bio
Date Reply #4 on Thu 30 May 2002 01:56 AM (UTC)
Message
I made a mistake and copied my original code, I meant to say in your code there is a slight error that if a person puts two semicolons in a row it will come out with a null argument, so to fix it, change:

if(*x == ';')
{
arg2[y] = 0; // terminate arg2
interpret(ch, arg2); // interpret it
y = 0; // start at start of arg2 again
} // end of semicolon found

to:

if(*x == ';')
{
arg2[y] = 0; // terminate arg2
if (arg2 [0] != '\0') // if not empty
interpret(ch, arg2); // interpret it
y = 0; // start at start of arg2 again
} // end of semicolon found

Basically just adding a check to make sure arg2 is not empty before interpreting it.

Thanks,
Jay
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


3,696 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]