Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Bing, Remcon, Google

Members: 1
Guests: 16
Stats
Files
Topics
Posts
Members
Newest Member
481
3,734
19,364
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Elseif
Forum Rules | Mark all | Recent Posts

Elseif
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 11, 2010, 3:45 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Posting this here since it covers all the bases hosted here... Anyway.

It dawned on me today. Why in the hell haven't any of us added support to any of these bases for something like elseif? But seriously, does:

>speech_prog test
if wearingvnum($n) 394
   if rand(17)
      mpe Random ONE
   elseif rand(20)
      mpe Random two
   elseif rand(25)
      mpe Random three
   elseif rand(33)
      mpe Random four
   elseif rand(50)
      mpe Random FIVE
   endif
endif

Not look a lot better than:
>speech_prog test
if wearingvnum($n) 394
   if rand(17)
      mpe Random ONE
   else
   if rand(20)
      mpe Random two
   else
   if rand(25)
      mpe Random three
   else
   if rand(33)
      mpe Random four
   else
   if rand(50)
      mpe Random FIVE
   endif
   endif
   endif
   endif
   endif
   endif
endif

?
I had a go at it, but I'm not familiar enough with the innards of the prog stuff to get it working right. I got it to the point where everything would parse into the proper places and what not, but it was still demanding an endif for every elseif. And that really wasn't the goal. So if anyone else wants to have a crack at it, I'd be more than willing to include it in all the FUSS bases, and I'm sure Remcon would be more than willing to add it to LoP. Hell, that might even be something Samson would add to AFKMud. :P
       
Post is unread #2 May 11, 2010, 4:51 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Yes, it would be something I'd want added to AFKMud. Unfortunately, like you, I don't understand how the prog parser works and you probably got father with it than I would have.

elseif is a wonderful thing in PHP and in Oblivion's scripting language, and it would definitely be nice to have in mudprogs too.
       
Post is unread #3 May 20, 2010, 10:39 am
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

I'm still not making any progress on this, anyone else figure out how to get elseif to work with these damned progs yet?
       
Post is unread #4 May 21, 2010, 12:55 pm
Go to the top of the page
Go to the bottom of the page

Darrik
Fledgling
GroupMembers
Posts20
JoinedJan 29, 2008

From looking through the code ( without trying to actually do it ), it appears there are two places where things would need to be changed, and there are two different ways I can think of to do it, the hard way ( add the handling for 'elseif' in it's combined form in both mprog_do_command and mprog_driver ), or the hacked way - which I actually like better since it would still be fully functional but not nearly as much work - which is just to force the driver to process the else and if separately.

The hacking way:
The mprog_do_command function
Add an if statement checking for elseif, returning FOUNDELSEIF ( you'll need to declare it at the top of the file, too ).

The mprog_driver function:
Add a case in the switch statement for FOUNDELSEIF just before FOUNDELSE. The lines processed in this case statement remove the 'else' part of the elseif from the variable 'cmnd' and stop the while statement from advancing to the next line. I would add another boolean named 'noadvance' or a prettier name and check for it before processing the code that advances the line, which is this code at the beginning of the while loop:

   /* With these two lines, cmnd becomes the current line from the prog,
       and command_list becomes everything after that line. */
    cmnd         = command_list;
    command_list = mprog_next_command( command_list );

    /* Are we at the end? */
    if ( cmnd[0] == '\0' )
    {
      if ( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] )
      {
        progbug( "Missing endif", mob );
      }
      --prog_nest;
      return;
    }


Lastly, don't put a break at the end of the FOUNDELSEIF statement, so it goes right into the FOUNDELSE statement.

This would remove the 'else' from the 'elseif (statement)' check for the standard errors for 'else' and leave 'if (statement)' to be processed the next run through the while statement.

Wouldn't this work? It's possible I'm missing something major, of course, but it looks like that should do it.

DV
       
Post is unread #5 May 21, 2010, 5:23 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

I'll take care of this.
       
Pages:<< prev 1 next >>