Author Topic: Help with updates and while loops please  (Read 549 times)

Offline Orangecat

  • Level 2
  • *
  • Posts: 3
  • Reputation: +0/-0
    • View Profile
Help with updates and while loops please
« on: February 24, 2011, 08:13:34 PM »
Hi there, I've read the tutorials on this site about making a browser based game and they've been very helpful!

I'm another one of the gazzilion people out there trying to make a pet game, my niche is show dogs, and while I've been able to understand how to get the game set up with users, and dogs in the database, I cannot seem to wrap my brain around how to code the part that lets the users "train" the dog.

It's driving me up the wall. I've watched so many php tutorials on youtube my eyes hurt. I get the "idea" of how to do it, but writing the actual code has been harder than I thought. I think if I can get this first part under my belt the rest will be easier. Hopefully.

Anyway, my problem is I'd like users to be able to click three buttons (training, socialization, condition) and have each of those buttons raise the appropriate numbers for that section. A dog might start with 1 in condition for example and then when you click the button it will go up to 2.

(in the long run I'd like the amount it goes up to be slightly random, for now I'll be happy with just getting it to work at all!)

If anyone is willing to point me in the right direction I'd really appreciate it. I suspect I'll need to run an update query and use a while loop...but then my brain quits.

Thanks!

Offline chrisjenkinson

  • Level 10
  • *
  • Posts: 61
  • Reputation: +0/-0
    • View Profile
    • Xiphos
Re: Help with updates and while loops please
« Reply #1 on: February 24, 2011, 10:45:58 PM »
Have a look at my rock/paper/scissors script, which is similar to what you want.

http://starglade.org/rps.php

http://starglade.org/rps.phps

Offline Orangecat

  • Level 2
  • *
  • Posts: 3
  • Reputation: +0/-0
    • View Profile
Re: Help with updates and while loops please
« Reply #2 on: February 25, 2011, 10:22:52 AM »
That does seem similar, but then I would need to insert/update/display/etc it into the database correct? I know this is basic stuff but I'm having a hard time getting it to sink in.

So, thinking out loud here...I would need an if statement for when they click the button, right? And a while loop to update the numbers, and then a mysql query to update the stats and display the new ones....am I on the right track there?

I don't know why this is so difficult for me, I'm a little frustrated that I can't seem to get it and just code this. I know html/css and never had any problem learning it, but this coding stuff is more involved than I thought it would be.

Anyway, I'm rambling. Thank you for the reply!


Offline CygnusX

  • Level 24
  • *
  • Posts: 304
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Help with updates and while loops please
« Reply #3 on: February 25, 2011, 10:28:39 AM »
That sounds about right.  I would start by becoming familiar with how data is sent from your PC to the Server and back.  For example, you would make a file called test.php that contains the following code:

<?php

global $_GET;
echo $_GET['v'];

?>

then type localhost/test.php?v=4 into your browser

This should display the value of 4 to your screen (given that you have WAMP or some other server software installed properly). 

You can change the value in the url and see different values printed to the screen.  Understand these fundamentals, then move on to database storage, logic, etc. 

Offline andrewjbaker

  • Level 17
  • *
  • Posts: 154
  • Reputation: +2/-0
    • View Profile
    • Fleeting Fantasy
Re: Help with updates and while loops please
« Reply #4 on: February 25, 2011, 05:50:49 PM »
Orangecat, without trying to sound disparaging, have you considered creating a few simpler games/Web sites first?

If I didn't make the suggestion, I'd fear the community might be performing a disservice to you.
Currently working on an HTML5 canvas 2.5D landscape renderer and a PBBG that uses it (http://fleetingfantasy.com/). The development blog's at http://fleetingfantasy.wordpress.com/.
What are BBGameZone members working on? See the game list.
irc.freenode.net, #bbg

Offline Orangecat

  • Level 2
  • *
  • Posts: 3
  • Reputation: +0/-0
    • View Profile
Re: Help with updates and while loops please
« Reply #5 on: February 25, 2011, 06:16:08 PM »
I actually got that part running, it's not pretty but it works. (whooohoo!)

Andrew, if I had any other interest in different games I'd take your suggestion. Unfortunately, I'm only learning how to program to create this one particular game. So, on I go.

It'll probably take me next to forever to get it finished, but I don't have a deadline. One good thing I have going for me is that I'm stubborn, and I google with the best of them, so eventually I muddle through. It just takes me longer than someone who knows what they're doing.

Now I need to figure out how to make it so users can only update the training once every 24 hours....that's the next thing on my list that will probably make me curse, LOL

But hey, by the time I get done, I'll be one awesome coder!! haha
« Last Edit: February 25, 2011, 06:23:35 PM by Orangecat »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal