Molarmite Posted May 8, 2007 Share Posted May 8, 2007 How do you get all of those things above to increase or decrease depending on where you go? I already got a database with all those created, now I need to make like a hospital where HP goes up, a store where Money goes down, etc. Can anyone help me out with this? Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/ Share on other sites More sharing options...
Nameless12 Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-248357 Share on other sites More sharing options...
Molarmite Posted May 8, 2007 Author Share Posted May 8, 2007 What is OOP? I know its Object-oriented programming, but what exactly does it do and is it similar to PHP? Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-248359 Share on other sites More sharing options...
Nameless12 Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-248383 Share on other sites More sharing options...
Molarmite Posted May 10, 2007 Author Share Posted May 10, 2007 I looked at that and it doesn't really help me out. A more simple way of stating my question would be how do you raise or lower values? Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250019 Share on other sites More sharing options...
genericnumber1 Posted May 10, 2007 Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250024 Share on other sites More sharing options...
Molarmite Posted May 10, 2007 Author Share Posted May 10, 2007 Well what do I if there's a room such as a hospital where it raises anyone's HP who goes in there. You can't specify an ID number there because multiple people can use it. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250036 Share on other sites More sharing options...
genericnumber1 Posted May 10, 2007 Share Posted May 10, 2007 store the current user's ID or username in a session when they login UPDATE users SET health = 100 WHERE username = '$_SESSION['username']' Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250038 Share on other sites More sharing options...
Molarmite Posted May 10, 2007 Author Share Posted May 10, 2007 Could you help me out some more. I'm new to PHP and not exactly sure where to put it or what else to add. I do better learning by visual examples. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250039 Share on other sites More sharing options...
obsidian Posted May 10, 2007 Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250074 Share on other sites More sharing options...
genericnumber1 Posted May 10, 2007 Share Posted May 10, 2007 well of course, things are easier to maintain, visualize, etc... it's just that procedural works, he said you HAD to use OOP, which just isn't true. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250188 Share on other sites More sharing options...
utexas_pjm Posted May 10, 2007 Share Posted May 10, 2007 Only crappy software like Linux, Apache, MySQL and PHP are written using procedural code. :-p Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250198 Share on other sites More sharing options...
trq Posted May 10, 2007 Share Posted May 10, 2007 Only crappy software like Linux, Apache and PHP are written using procedural code. :-p Hehe... its funny cause its true. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250199 Share on other sites More sharing options...
Nameless12 Posted May 11, 2007 Share Posted May 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250257 Share on other sites More sharing options...
utexas_pjm Posted May 11, 2007 Share Posted May 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250264 Share on other sites More sharing options...
Nameless12 Posted May 11, 2007 Share Posted May 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250274 Share on other sites More sharing options...
obsidian Posted May 11, 2007 Share Posted May 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50544-doing-hp-exp-and-money-in-rpgs/#findComment-250490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.