View Single Post
  #7  
Old 08-16-2013, 12:17 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
On an unrelated note you may want to create some getter and setter functions instead of doing things such as

PHP Code:
clientr.exp += this.expgain
It helps if you want to add some validation or a new variable to how it's calculated later on such as experience potions or checks to make sure they do not level past the max level. The main reason you would want to use getter and setter functions is if you need to go change something such as the flag name or whatever formula you use to calculate the experience you wont need to go back and modify every line of code that adds experience. I'm at work so if it doesn't make too much sense I can reexplain later if Chris Vimes hasn't already answered your questions

join the player to a class called player_functions or whatever you want to call it doing player.join("player_functions"); Then within that class do something similar to the following

PHP Code:
function addExp(amount){
  
clientr.exp += amount;

then whenever you need to add experience you can do

PHP Code:
player.addExp(8675039); 
Then if you want to add checks later you can just do the following in player_functions instead of going back and modifying 100 times in all your code

PHP Code:
public function addExp(amount){
  
temp.exptable = { 0102040,75100 };
  if (
clientr.exp amount <= temp.exptable[clientr.level]){
    
clientr.exp += amount;
  } else 
player.levelUp();
}

function 
levelUp(){
  
clientr.level++;
  
clientr.exp 0;

This also helps prevent unneeded code duplication

Last edited by Cubical; 08-16-2013 at 08:16 PM..
Reply With Quote