Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Condensing code?
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Condensing code?
(07-15-2013 02:44 PM)a.live Wrote:  but I couldn't get then Less than or Equal to conditional to work.
So what happens when you try to use it?

I'm not entirely sure what your conditionals are trying to achieve, there's a lot of logic in there after all.
Yes, I'd use numbers, and, looking at a few things, probably put them into a sorted array so that you don't have to write for every single combination of inputs.
This may be going a bit beyond simple template conditionals though.

Conceptual PHP:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$skill2num = array('None' => 0, 'Novice' => 1, 'Apprentice' => 2, 'Adept' => 3, 'Venerated' => 4, 'Virtuoso' => 5);
$levels = array(
  (int)@$skill2num[$userfields['fidAA']],
  (int)@$skill2num[$userfields['fidBB']],
  (int)@$skill2num[$userfields['fidCC']],
);
sort($levels);

if($levels[0] == 0 && $levels[1] == 0) {
  // do nothing
} elseif($levels[0] == 1 && $levels[1] == 1 && $levels[2] >= 1) {
  echo 'Novice skill';
} elseif(($levels[0] == 1 || $levels[0] == 2) && $levels[1] == 2 && $levels[2] >= 2) { // unsure if this is correct, I'm too lazy to check through the entire conditional
  echo 'Apprentice skill';
}
// etc


My Blog
(This post was last modified: 07-16-2013 11:51 AM by ZiNgA BuRgA.)
07-16-2013 11:44 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Condensing code? - a.live - 07-15-2013, 02:44 PM
RE: Condensing code? - ZiNgA BuRgA - 07-16-2013 11:44 AM

 Standard Tools
Forum Jump: