Jump to content

Recommended Posts

You need oop for this. On a small scale think of it like this. You have a room object and you can place objects inside that room object. Because all the objects are grouped together in the room it is very easy to adjust attributes on certain types of objects.

 

 

that is a big question to answer, in short you have objects that are made from classes. Or in other words you have objects made from blueprints. Another way of looking at them is a group of related functions and properties but there is much more to them then that.

 

<?php
class Person 
{
   public $health = 100;

   public function hurt(Person $person)
   {
          $person->health -= 25;
   }

   final public function is_alive()
   {
      if ($this->health > 0)
          return true;
   }
}

$someone = new Person();

$someone_else = new Person();

$someone->hurt($someone_else);
$someone->hurt($someone_else);
$someone->hurt($someone_else);
$someone->hurt($someone_else);

if ($someone_else->is_alive()) {
  echo 'not dead yet';
} else {
  echo 'dead';
}

class Really_Strong_Person extends Person 
{
   public $health = 500;
}
?>

 

I hope this example helps.

you don't have to use oop to do this, or pretty much anything for that matter... procedural works fine...

 

just do a query, Molarmite

 

UPDATE users SET health = 100 WHERE userID = {userid}

 

of course you would put in the user's userid or username or however you specify who they are in your table.

you don't have to use oop to do this, or pretty much anything for that matter... procedural works fine...

 

It's the fine that is the problem in this statement. If you have something that works fine and something that works wonderfully, I would hope you would opt for the better of the two. While it's true that you can get just about anything done with procedural programming, you'll be much better off taking the time to learn how OOP will do things better - especially for something like an RPG where you're doing the same actions hundreds or even thousands of times.

i may of had my wording a little wrong but it was always my intent that there were both ways and oop was just the correct way. You can create anything you can create in oop in procedural but you can also create whatever you want to create in assembly. But we all know it would not be a good thing to do that for obvious reasons...

 

When I ask you how you are going to go about having multiple cities, towns etc... you are probably going to think "I can do that with procedural", you will instantly think I will just create database tables and each city will have a row in a table... But what happens when I take away your database, will you still be able to do it?? Maybe you will be able to get away by just using a really large array for each city and then it becomes arrays vs objects.

 

And as a side note I find most people within the php community who knock oop have not actually become proficient with it.

And as a side note I find most people within the php community who knock oop have not actually become proficient with it.

 

I agree with this statement.  However I think that the same can be said of people who knock procedural code.  I am from the generation whose first CS class was taught exclusively in Java, a language which forces the use of object oriented paradigms.  For a long time I thought that OOP was inherently superior to procedural programming --I've come to learn that they are just different (how's that for cliche'?).  People, especially those in the PHP community, who have learned OOP develop an arrogance and refuse to accept that a scalable, efficient, maintainable application can be built outside of an MVC framework.  At the same time, as Nameless pointed out, SOME people who put off learning about OOP make excuses not to learn citing meager increases in performance by not introducing the overhead of an OO framework.  Everyone has a coding preference, mine happens to be OO, I think it is important not to let your preference become a bias that prevents you acknowledging the validity of alternate approaches.  I guess all this really boils down to "Can't we all just get along?" and when defending your chosen approach don't be so closed minded that you see your approach as the only valid approach, afterall that's how things like Windows ME happen.

 

Best,

 

Patrick

Yeah I pretty much agree with everything you said but when it comes to the personal preference thing I agree that most people have a preference for one over the other but I don't think this needs to be the case. Simple tasks that require one function are best suited to functions and things that require more than one function are usually best suited to object oriented programming. I don't think it should be a choice between one or the other because they compliment each other so well.

 

I think that the same can be said of people who knock procedural code.  I am from the generation whose first CS class was taught exclusively in Java, a language which forces the use of object oriented paradigms.  For a long time I thought that OOP was inherently superior to procedural programming --I've come to learn that they are just different (how's that for cliche'?).

 

Well said! I agree wholeheartedly with this. I learned PHP on my own, using books that were rampant with procedural code, so I was in for a rude awakening when I got into Java and C++ and was required to immerse myself into the OOP world. Each definitely has its place in coding, and one is not superior to the other, but there are definitely very obvious uses for each and each has its place. There are some situations (IMHO, this RPG question is one of those) where using procedural code is like using a sledgehammer to get a square peg into a round hole. It can most definitely be accomplished, but the ease of use and modification of the code would be such as to discourage any further development on the foundational system.

 

On the other hand, there are also often projects on which I work that taking the time to plan and implement an OO approach would be entirely overkill or just simply a waste of time because the additional functionality is not needed. In these cases, the same analogy could be applied.

 

Each has its place, that's for sure.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.