Author Topic: Selectable Races  (Read 698 times)

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Selectable Races
« on: January 19, 2009, 07:40:02 AM »
One thing i wanted as a option for my game was various races, which is not covered in the basic tutorial. So with some good ol fashion googlin here is what i have so far

Code: [Select]
            Username: <input type='text' name='username' id='username' value='{$smarty.post.username}' /><br />
            Password: <input type='password' name='password' /><br />
            Confirm Password: <input type='password' name='confirm' /><br />
            Race:<select race_id="select" size="1">
<option value="1">race1</option>
<option value="2">race2</option>
<option value="3">race3</option>
<option value="4">race4</option>
<option value="5">race5</option>
</select>
            <input type='submit' value='Register!' />
           
        </form>
        <script type='text/javascript'>
        document.getElementById('username').focus();
        </script>
    </body>
    </html>

Now as you can see i hard coded the options into the page(its the registration.tpl) so changing the value on this particular page at a later date is of no concern as of yet.

Also altering the registration.pgp
Code: [Select]
            $query = sprintf("INSERT INTO users(username,race_id,password) VALUES ('%s','%s','%s');",
                mysql_real_escape_string($_POST['username']),
                mysql_real_escape_string($_POST['race_id']),
                mysql_real_escape_string(md5($password)));
               
            mysql_query($query);           
            $message = 'Congratulations, you registered successfully!';

All of which seems to work without error(still amazed on the no error part). But my issue is I am unclear how I am to make the selected race so that it can $_post to the db along with username and pw. in short i have the form ready, just need to know how to get it from the selected form, and posted into the database.
People Like You, Are the Reason People Like Me Need Medication

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Selectable Races
« Reply #1 on: January 19, 2009, 08:33:51 AM »
Shouldn't it just be part of the same insert used on the character table?
Idiocy - Never underestimate the power of stupid people in large groups.


Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: Selectable Races
« Reply #2 on: January 19, 2009, 08:40:53 AM »
Yes thats where it is going i have the tutorial basic setup for the db

uniqueid
username
password
race_id

the goal is to make the registration for post to the user table, and for other usages  say applying race bonus etc, i have also created races table, that i will be able to pull the bonus etc from.The thinking with this design was long term, assigning race at registration keeping it elsewhere from race bonus's/attributes so that down the road was to keep balance in game ex one race has a dominant population,can put into effect a voluntary race change, or if need be move a entire clan. Also thinking even farther ahead if the game ever took off, I could implement a marginal fee for race change one every cycle of the game.
« Last Edit: January 19, 2009, 09:11:54 AM by AcidicOne »
People Like You, Are the Reason People Like Me Need Medication

Offline bbgames

  • Level 16
  • *
  • Posts: 138
  • Reputation: +1/-0
    • View Profile
    • Building Browsergames
Re: Selectable Races
« Reply #3 on: January 19, 2009, 09:45:17 AM »
Are you having trouble making 'race_id' show up in $_POST? If you are, that's because of this line of HTML:
Code: [Select]
<select race_id='select' size='1'>
You need to change it to this:
Code: [Select]
<select name='race_id' size='1'>
Once you've done that, you should be able to use $_POST['race_id'] just fine.

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: Selectable Races
« Reply #4 on: January 19, 2009, 09:53:33 AM »
Worked Like a Charm, can't believe it was something so simple....
« Last Edit: January 19, 2009, 10:00:29 AM by AcidicOne »
People Like You, Are the Reason People Like Me Need Medication

Offline FirePenguins

  • Level 10
  • *
  • Posts: 59
  • Reputation: +0/-0
    • View Profile
    • The Iron Helm
Re: Selectable Races
« Reply #5 on: January 19, 2009, 10:31:10 AM »
One thing i wanted as a option for my game was various races, which is not covered in the basic tutorial.

Is this a basic tutorial here on bbgamezone?  I hear people mention these tutorials but I don't think I've ever seen them?

Offline AcidicOne

  • Level 16
  • *
  • Posts: 147
  • Reputation: +0/-0
    • View Profile
Re: Selectable Races
« Reply #6 on: January 19, 2009, 10:34:20 AM »
no multiple races was not covered in the tutorials, but here is the link to the ones that are available, and am sure from the post above you could easily add multiple races yourself using the tutorial and the code i have implemented aboove.

http://buildingbrowsergames.com/tutorials/
People Like You, Are the Reason People Like Me Need Medication

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal