Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
umdbandit
Wanderer


Joined: 31 Oct 2004
Posts: 94

PostPosted: Thu Nov 09, 2006 5:49 am   

Object Oriented approach to CMUD
 
Well I've been letting this license sit here and rot on my computer while i've opened CMUD maybe once or twice.

Anyways, I think i'm finally biting the bullet and switching over. I script a great deal, and figure I might as well switch over before i get left behind :P

So i'm not going to ask any conversion questions, because other than my map file, I think i am going to start entirely from scratch.

Before I dive in completely, I want to give a shout out there and see if anyone has taken an object oriented approach to CMUD scripting. If so, please respond to my post or PM me.

thanks like always

-umdbandit
_________________
Rufus- Winner of Stuff
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Nov 09, 2006 6:20 am   
 
You'll have to explain what you mean a lot better than that, Rufus. CMud's, and ZMud's before that, scripting language is already object-oriented.
_________________
EDIT: I didn't like my old signature
Reply with quote
umdbandit
Wanderer


Joined: 31 Oct 2004
Posts: 94

PostPosted: Thu Nov 09, 2006 6:44 am   
 
Well first off, i'd be pretty reluctant to call Zmud object oriented.

Anyways, i'm basically just curious if people have been making blackbox objects in CMUD. I dont really have any questions, I just want to see what people are up to.
_________________
Rufus- Winner of Stuff
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Thu Nov 09, 2006 10:00 am   
 
I made a few blackbox functions in zMUD - the syntax is such that they aren't very easy to read though. With multi-line scripts in CMUD that might be a bit better.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Nov 09, 2006 1:57 pm   
 
I'm making more and more black boxes.
Really though most of the things I do are task specific. One noteable black box I made was for converting numbers from say sixty-seven to 67. Yes I know that is a specific task. But as a black box now I can use it in all my other scripts. *the point of black boxes*
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Thu Nov 09, 2006 4:28 pm   
 
However, I don't agree that zMUD's or CMUD's scripting language is object-oriented. I suppose you just mean coding in a re-usable way. i.e. such that code can be used (e.g. by using blackbox functions).
Reply with quote
umdbandit
Wanderer


Joined: 31 Oct 2004
Posts: 94

PostPosted: Thu Nov 09, 2006 4:54 pm   
 
Arminias,

are you doing it a la zmud style and using aliases?

or do you have a better way :)
_________________
Rufus- Winner of Stuff
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Nov 09, 2006 5:35 pm   
 
There are ways to "fake" object-oriented in zMUD/CMUD by playing tricks with class folders. It's not true OOP, but you can end up with similar behavior. Unfortunately, it makes scripts a real pain to figure out sometimes and enabling/disabling classes to change how a particular alias might work can really make your scripts complicated.

Remember that zMUD/CMUD scripting is meant to be learned by non-programmers. I try to fight the tendancy to make it into a "real" language that will scare people away. CMUD does more of this than zMUD and I'm already receiving negative comments about it.

Just look at how hard concepts like packages and modules are for a lot of people around here. Imagine trying to get people to do OOP. I remember when I first learned OOP many many (many :) years ago, and remember that I thought my head was going to explode (until I finally had that ah-ha moment).

Anyway, what I'll probably recommend is that people use stuff like ActivePython in CMUD if they want that kind of power (once the alternate scripting language stuff is working, which it's not yet).
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Nov 09, 2006 6:38 pm   
 
umdbandit wrote:
Arminias,

are you doing it a la zmud style and using aliases?

or do you have a better way :)


Sometimes I do it with functions sometimes I do it with an alias and store the return values in a variable then reference the variable later.

But when we get real return statements I'll do that of course.

A function as we do have them in zmud can be used for several things we can use the predefined functions Zugg gave us or other functions we have made ourselves inside the new function.

For the one I mentioned, the number converter, I use an alias and a variable for the return.

Still though, you can write in an object oriented style in any language. Some languages are just better suited to it than others.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Wed Jun 17, 2009 3:45 am   
 
Zugg wrote:
There are ways to "fake" object-oriented in zMUD/CMUD by playing tricks with class folders. It's not true OOP, but you can end up with similar behavior. Unfortunately, it makes scripts a real pain to figure out sometimes and enabling/disabling classes to change how a particular alias might work can really make your scripts complicated.

Remember that zMUD/CMUD scripting is meant to be learned by non-programmers. I try to fight the tendancy to make it into a "real" language that will scare people away. CMUD does more of this than zMUD and I'm already receiving negative comments about it.

Just look at how hard concepts like packages and modules are for a lot of people around here. Imagine trying to get people to do OOP. I remember when I first learned OOP many many (many :) years ago, and remember that I thought my head was going to explode (until I finally had that ah-ha moment).

Anyway, what I'll probably recommend is that people use stuff like ActivePython in CMUD if they want that kind of power (once the alternate scripting language stuff is working, which it's not yet).



I hate to resurrect an old thread, but I was thinking about this a lot lately and trying to come up with ways to do this. There are a lot of times when I really wish I could take a real OO approach when creating something. My question is what do you mean when you say "fake it"?

Also I know what you mean regarding "Remember that zMUD/CMUD scripting is meant to be learned by non-programmers. I try to fight the tendancy to make it into a "real" language that will scare people away." However, in my experience this is the first taste for many people with scripting or writing code period. I think it is a great way to learn those fundamentals they can use later on and instead of just procedural scripts it would be nice to have OOD.

I tried to create some sort of object oriented design but I am wondering if you all know of things I don't.

My example:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="Body" copy="yes">
    <class name="LeftLeg" copy="yes">
      <var name="status" type="Integer" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @LeftLeg/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @LeftLeg/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>LeftLeg/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <func name="Body" copy="yes">
      <value>#class Body/$class
#variable status "" "" $class
#function getCure {#return %db(@Body/cure,@$class/status)} $class
#function getStatus {#return @$class/status} $class
#function setStatus($state) {$class/status = $state} $class
#class 0</value>
      <arglist>$class</arglist>
      <notes>Constructor

Obviously you can't do
Body  rightLeg = new Body(args);

Had to recreate the same variables and functions in each subclass to make them like instantiated objects. </notes>
    </func>
    <class name="RightLeg" copy="yes">
      <var name="status" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @RightLeg/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @RightLeg/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>RightLeg/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <class name="RightArm" copy="yes">
      <var name="status" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @RightArm/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @RightArm/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>RightArm/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <class name="LeftArm" copy="yes">
      <var name="status" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @LeftArm/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @LeftArm/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>LeftArm/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <class name="Torso" copy="yes">
      <var name="status" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @Torso/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @Torso/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>Torso/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <class name="Head" copy="yes">
      <var name="status" usedef="true" copy="yes">
        <value>0</value>
        <default>0</default>
      </var>
      <func name="getCure" copy="yes">
        <value>#return %db( @Body/cure, @Head/status)</value>
      </func>
      <func name="getStatus" copy="yes">
        <value>#return @Head/status</value>
      </func>
      <func name="setStatus" copy="yes">
        <value>Head/status = $state</value>
        <arglist>$state</arglist>
      </func>
    </class>
    <var name="cure" type="Record" copy="yes">
      <value>1=restoration|2=mending|3=epidermal</value>
      <notes>1 = mangled/lacerated
2 = broken
3 = slashed</notes>
    </var>
  </class>
</cmud>


I tried to make this like Java. I can't really instantiate a new object in my script so I just created subclasses of the Body class. The only way I could use the same attributes and behaviors would be to recreate them in each subclass too. I also tried to create a constructor of sorts. However, I think the way I did it here does kind of resemble OOP since I used the full path names then for example the RightLeg object won't return the state of the LeftLeg etc.

So to use it I could do:

Code:
#if (@Salve/canApply()) {
  #switch (@Body/Head/getStatus()) {
    $cure = @Body/Head/getCure()
    #call @Salve/apply( $cure, "head")
    }
    (@Body/LeftLeg/getStatus()) {
    $cure = @Body/LeftLeg/getCure()
    #call @Salve/apply( $cure, "legs")
    }
    (@Body/RightLeg/getStatus()) {
    $cure = @Body/RightLeg/getCure()
    #call @Salve/apply( $cure, "legs")
    }
    (@Body/LeftArm/getStatus()) {
    $cure = @Body/LeftArm/getCure()
    #call @Salve/apply( $cure, "arms")
    }
    (@Body/RightArm/getStatus()) {
    $cure = @Body/RightArm/getCure()
    #call @Salve/apply( $cure, "arms")
    }
    (@Body/Torso/getStatus()) {
    $cure = @Body/Torso/getCure()
    #call @Salve/apply( $cure, "torso")
    }
  }


The above seems to work great, but is this what you mean when you say fake it? Or are there much better ways?
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net