TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-31-2009, 08:00 PM   #1 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default call function and change variables?

I want to make a character builder for a tabletop game system I enjoy but when making a character there are selections you need to make that effect a series of skills. Is there a way to do something like this below well?

Code:
if picks_background { 
   $var1 = "x";
   $var2 = "y";
  }
How do you return those variables correctly? The thing is there might be anywhere from 10 to 20 things effected by selecting a specific background. A different background might not even have the same variables listed, it might have var6 and var9 instead.
__________________
I am not a programmer, nor do I play one on tv.
nefus is offline  
Reply With Quote
Old 12-31-2009, 11:15 PM   #2 (permalink)
The Visitor
 
tdub311's Avatar
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
tdub311 is on a distinguished road
Default

You could return them in an array like so:

if picks_background {
$var1 = "x";
$var2 = "y";
$vars = array("var1"=>$var1, "var2"=>$var2);
return $vars;
}
tdub311 is offline  
Reply With Quote
Old 01-01-2010, 01:19 AM   #3 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

So your suggestion would be to return an array. Then I'd have to query the array to find out what was in it I guess.... hmmm...
__________________
I am not a programmer, nor do I play one on tv.
nefus is offline  
Reply With Quote
Old 01-02-2010, 03:32 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

There are a number of ways to do this, objects are probably the most efficient. If you are not using objects anywhere else, don't bother with this. But here is how I would do it based off of what I know (this is not tested and is merely for methodical purposes)

Charicter Definitions:
Archer - speed: 10, attack: 15, range: 15, rateOfFire: 10, armor: 3
Swordsman - speed: 15, attack: 25, armor: 50

class.php
PHP Code:
class player
{
function 
_construct{
//pseudo code
foreach(name and value in $playerDefFile)
{
$playerSkills[name]=value;
}
 
public 
$playerName//String
private $playerDefFile;
private 
$playerSkills as array('n/a'=>"speed"'n/a'=>attack'n/a'=>"range"'n/a'=>"rateOfFire"'n/a'=>"armor"'n/a'=>");

archer.def
Code:
speed: 10
attack: 15
range: 15
rateOfFire: 10
armor: 3
swordsman.def
Code:
speed: 15
attack: 25
armor: 50
This will make any non-used attributes equal to 'n/a' so the program can later on see if that attribute can be used. This also gives you a generic base for all your types of players so you can have multiple ones in an game (thus being a generic aproach) and you can add/modify players without any code changes (thus being an explansible one).

ps. I do have some experience in C++ game development, so I've programmed generic players before.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
nefus (01-02-2010)
Old 01-02-2010, 04:11 AM   #5 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

Now thats a whole different angle than the one I considered. Below is sort of how I was starting to construct the function.

Code:
function barbarian_background(){
    $background = array("Athletics"=>'10', "Perception"=>'5', "Resilience"=>'10', "Stealth"=>'5');
    return $background;
        }
$background = barbarian_background();

print_r($background);

if(array_key_exists("Athletics", $background)) {
    echo "<br> Bingo!  Athletics is there.  Currently it's at a ".$background["Athletics"].".  Let's update that to ";
    $background["Athletics"] =  $background["Athletics"] + 5;
    echo $background["Athletics"].".";
    
    }
I'm just not sure how to handle things like picking 2 of 5 possible skills to add 5 bonus points to at this point. Or picking 1 of 6 possible new skills yet. I'm sure I can figure it out though, still I am open to suggestions.
__________________
I am not a programmer, nor do I play one on tv.
nefus is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Creating a Simple Currency Converter with Automatic Symbols Wildhoney General 11 03-16-2010 05:22 PM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM


All times are GMT. The time now is 02:29 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design