Jump to content

Need some help with my very frist script


CoffeeAddict

Recommended Posts

Hello, I'm here hoping that someone can help me sort out a few things. I'm working on a virtual pet game, I know I can hear you groaning from over here. "Not another delusional person who thinks they can run a neopets site!"

 

No. I don't want a neopets site, in fact I've never played it. I'm focusing instead on dog lovers that want to own, train, breed, and show their own virtual purebred dogs. I know it's been done, and I'm not trying to re-invent the wheel here. I just think, or should I say hope, that I can create something equally as entertaining and maybe a little better in the long run.

 

So, now that you know my life story, here's what I need help on. I'm trying to start small, very small. I'm quite new to PHP and I've been told that's what I'll need to use in order to create this game.

 

I've been through about a half dozen basic tutorials and thanks to my good memory I think I understand at least 80% of what I read and practiced. However, I'm still having trouble writing the first line of code.

 

The first function (I think it's called a script, right?) I want to code will allow the user to click a button, which will "train" the dog, and automatically raise the dog's virutual obedience level. So, say the dog is just starting training and he's got an obedience level of zero. When the person clicks the button to train, the level will go up 2 increments. It should continue like that untill the user has "trained" the dog at least four times, then since the dog has more experience in learning, his obedience level will go up faster by increments of 3 for the next 3 times the "train" button is clicked, and so on and so forth untill the obedience level reaches 20.

 

How the heck do I code this? I'm not even sure where to start. I think I might have to uae a function, and maybe an "if else" statment?

 

I think this should be something easy to code for someone who knows what they're doing, but right now that isn't me. I'm really looking at this whole game construction as a learning experience, once I get this first step down, I can move on and learn how to code the next feature, etc.

 

If anyone can help me out with this one thing, I would be very greatful. I can read basic tutorials untill I'm blue in the face, but I need someone to tell me how to apply what I've learned so it works for the feature I want to create.

 

And...sorry for the novel. I wanted to be complete in my description of what the problem is.

Link to comment
Share on other sites

That is actually one of the first decent virtual pet game ideas I have heard in a while. The idea of showing them instead of fighting them - I like it. I'd like to play it :) Although I'd prefer a cat version ;)

 

So here's some pseudo code:

<?php
///Get $obey from DB
if($obey < 20){
   if($obey < {
      $inc = 2;
   }else{
      $inc = 3;
   }
   $obey = $obey+$inc;
   //Save $obey to DB
}else{
//No more training
}
?>

 

Edit: If you don't have anything at all written yet, your first task is a user registration/login system - create a class for the users, one for the dogs, set up your database, etc.

Link to comment
Share on other sites

I think this will be a very valuable read for you, not to mention that it is almost exactly what you need! Hopefully it is not too confusing for you. You may want to go back a little in the Zend tutorials to pick up on the author's style and so forth. If you don't understand this now, don't worry too much. Use what Jesi gave you, get some lines under your belt and ease into it. No pressure.

 

http://devzone.zend.com/node/view/id/638

 

However, if you can begin to understand classes and functions, you will make your life much easier in the long run, and its just good knowledge to have. This will come in handy when the user get two dogs and breeds them to create puppies.

Link to comment
Share on other sites

Thank you so much for the responses. Jesirose, I'm confused on the "Get $obey from DB", the other stuff I understand. Does this mean I have to use a database to store information first?

If you want the user to be able to do something one day and come back the next, then you need to store the information. In this case, the database is holding the obedience level of the dog so when the user comes back, they don't need to start over with a puppy. Although its not the only choice, the database would be one (if not the best) option for someone getting started.

Link to comment
Share on other sites

Yes, you'll need to have a database to store all your user's info, as well as the dogs info, and other info. You might want to start with a smaller project honestly, but the first step for this is gonna be the user login like I said. There are some decent tutorials around about user logins. You're also going to need to read about SQL injection, user authentication, etc. (Otherwise how will you tell whose dog is whose, see?)

 

Good luck :)

Link to comment
Share on other sites

That makes sense. I should start with learning about user logins first and then go from there.

 

I know it seems like I'm biting off more then I can chew, and I probably am, but eventually after much curseing and coffee (and help from you guys  ;) ) I'm sure I'll figure it out in time. I'm not trying to get the whole game up and running next week. I know it'll take time to learn how to get everything working.

 

I'm going to go find some tutorials on databases and creating a user log in system. Thanks again!

Link to comment
Share on other sites

Well when I started my game, it took me about 9 months. (six of which I really worked on it.) - but I had also been using PHP for awhile.  It was pretty decent, ran for a year, I just recently shut it down to work on some other projects and a newer version.

 

You might enter the competition going on right now for some practice.

Link to comment
Share on other sites

That makes sense. I should start with learning about user logins first and then go from there.

 

No, don't do that. User logins are BORING especially to learn PHP with.

 

I think it'd be great to make a page with a picture of a dog and a button to train him/her.

 

When you click on the button it posts a form back to the page which increases the $train value.

 

We can tag the user stuff on later.

 

Start with the above. When that's working, you need to save the $train value into the database.

 

When that is working you need to work out some nice algorithms + do user stuff + and make a pretty site  :) :) :)

 

Do some fun stuff first. Coding shouldn't be a chore.

 

monk.e.boy

Link to comment
Share on other sites

monk.e, I agree that user logins can be a bit tedious, but if you write all the code to train the dog, and then add in users and data persistance, you're just going to have to rewrite it.

 

Well, hopefully not re-write all of it  ;D

 

But yeah, it's not the "computer science" way of coding, and I'd personally do it the way you say. Users. Sessions. Database. Login. Logout. All that before any pictures of dogs are shown  ;)

 

monk.e.boy

Link to comment
Share on other sites

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.