How to challenge a player ?

For the 1on1 Ladder on PlanetNexuiz

Moderators: Nexuiz Moderators, Moderators, Ladder Moderators

Postby tChr » Thu Mar 30, 2006 2:01 pm

esteel wrote:Hmm i have no idea how you will do the thing but remeber that you can toggle between two values quite easily by subtracting the current value from the sum of the two..
Exampe: values 7 and 9 (sum = 16), current = 7..
current = 16 - current (7) = 9.. use 9 as color
current = 16 - current (9) = 7.. use 7 as color
current = 16 - current (7) = 9.. use 9 as color
and so on..



Inside a loop, this is as effective as it gets:

Code: Select all
if ($curcolor == "#444444") $curcolor = "#888888";
else $curcolor = "#444444";
print $curcolor;


edit:
Yeas, i'm a self-thaught, real-life coder. That means I make things that works, and is effective, not necessarily the way a school teacher would do it :)

Edit2:
of cource you can exchange the color codes with CSS classes, a single number or whatever differentiates the colors.
the spice extend life!
the spice expand conciousness!
the spice is vital to space travel!
sooooo.. tell me what you want, waht you really-really want
I will proceed directly to the intravenous injection of hard drugs, please.
tChr
Forum addon
 
Posts: 1501
Joined: Tue Feb 28, 2006 9:11 pm
Location: Trondheim, Norway

Postby esteel » Thu Mar 30, 2006 2:22 pm

Well if it would work that way (not much php experience), this inside a loop
Code: Select all
$curcolor = "#bbbbbb" - $curcolor;
print $curcolor;

looks even simpler and i think it might be faster because there is no jump inside the code just a simple calculation ;) And once you know the basic concept behind it its not much harder to understand then your version. But in case it is: Ever heared of job-security???
Last edited by esteel on Thu Aug 31, 2006 7:35 pm, edited 1 time in total.
esteel
Site admin and forum addon
 
Posts: 3924
Joined: Wed Mar 01, 2006 8:27 am

Postby tChr » Thu Mar 30, 2006 2:32 pm

esteel wrote:Well if it would work that way (not much php experience), this inside a loop
Code: Select all
$curcolor = "#bbbbbb" - $curcolor;
print $curcolor;

looks even simpler and i think it might be faster because there is no jump inside the code just a simple calculation ;) And once you know the basic concept behind it its not much harder to understand then your version. But in case it is: Ever heared of job-security???

First of all, my method works for any string, and this will most likely be a string, since the formatting is generally done with CSS.

Second, you are trying to subtract a combined string of letters (#) and hexadesimal numbers (0-9A-F) from an other simiilar string. That wont work to well.

To achieve what you are trying you would have to do somthing like this
Code: Select all
$basecolor = "FFFFFF";
$curcolor = "222222";
*loop* {
$curcolor = $basecolor - $curcolor; (adapt HEX substraction some way)
}


This also limits your choice of colors significantly.

Job-security is a good thing :)
the spice extend life!
the spice expand conciousness!
the spice is vital to space travel!
sooooo.. tell me what you want, waht you really-really want
I will proceed directly to the intravenous injection of hard drugs, please.
tChr
Forum addon
 
Posts: 1501
Joined: Tue Feb 28, 2006 9:11 pm
Location: Trondheim, Norway

Postby esteel » Thu Mar 30, 2006 3:01 pm

Oh yeah, those were strings.. right, it does not work with them. I was thinking more in terms of other languages where you use numbers to identify colors.
But as long as you only want to toggle two numbers you are free to choose what numbers (as you just need the two numbers and the sum of both). Just check the example above. Or an other example: number1 = 22, number2 = 33, sum = number1+number2, current = 22, now this: current=sum-current; will toggle between 22 and 33. You can simply change those numbers it will still toggle (so it does not limit anything).
Well Green will surely find a way ;)
Last edited by esteel on Thu Aug 31, 2006 7:36 pm, edited 1 time in total.
esteel
Site admin and forum addon
 
Posts: 3924
Joined: Wed Mar 01, 2006 8:27 am

Postby tChr » Thu Mar 30, 2006 3:12 pm

esteel wrote:Oh yeah, those were strings.. right, it does not work with them. I was thinking more in terms of other languages where you use numbers to identify colors.
But as long as you only want to toggle two numbers you are free to choose what numbers (as you just need the two numbers and the sum of both). Just check the example above. Or an other example: number1 = 22, number2 = 33, sum = number1+number2, current = 22, now this: current=sum-current; will toggle between 22 and 33. You can simply change those numbers it will still toggle (so it does not limit anything).
Well Green will surely find a way ;)

Yeayh.. they are strings :) You could do your loopcalc.thing, and assign the colors in and array keyed by the number, but that'd be kinda pointless. unless you are using more than 2 colors.
The most common way to I've seen this done is like this:
Code: Select all
$n = 0;
*loop* {
if ($n >= 2) $n = 0;
if ($n == 0) $color = $color1;
else $color = $color2;
$n++
}

No I'm not kidding.. you see stuff like that all the time.
the spice extend life!
the spice expand conciousness!
the spice is vital to space travel!
sooooo.. tell me what you want, waht you really-really want
I will proceed directly to the intravenous injection of hard drugs, please.
tChr
Forum addon
 
Posts: 1501
Joined: Tue Feb 28, 2006 9:11 pm
Location: Trondheim, Norway

Postby GreEn`mArine » Thu Mar 30, 2006 3:15 pm

Code: Select all
now new in main.css:

.dark {background-color:#000000}
.bright {background-color:#1F1F1F}

in rankings.php:

....
<tr class="<? echo ($i%2?"dark":"bright"); ?>">
....


The code actually works, I have always <tr class="dark"> and <tr class="bright"> that changes all the time, however the page looks not like the screenshot does, there are "gaps" between the coloring of the grey background ... why ? how where you doing it in html to look like that, obi_wan ?
IRC quote:
[kojn] I've been coming a bit more recently
[kojn] she took it the dirty way
GreEn`mArine
Forum addon
 
Posts: 1509
Joined: Tue Feb 28, 2006 9:33 pm
Location: Germany

Postby tChr » Thu Mar 30, 2006 3:22 pm

GreEn`mArine wrote:
Code: Select all
now new in main.css:

.dark {background-color:#000000}
.bright {background-color:#1F1F1F}

in rankings.php:

....
<tr class="<? echo ($i%2?"dark":"bright"); ?>">
....


The code actually works, I have always <tr class="dark"> and <tr class="bright"> that changes all the time, however the page looks not like the screenshot does, there are "gaps" between the coloring of the grey background ... why ? how where you doing it in html to look like that, obi_wan ?

What browser do you use? Have you tried with other browsers? Have you set borer to 1px on td? that can make the border draw it self on top of the tr color.

edit:
I assume you use $i as your loopcount.. I always use foreach in php, so this would not work for me :) I never print html directly either, i return it, so adding echos is not an option. Nice solution though :)
the spice extend life!
the spice expand conciousness!
the spice is vital to space travel!
sooooo.. tell me what you want, waht you really-really want
I will proceed directly to the intravenous injection of hard drugs, please.
tChr
Forum addon
 
Posts: 1501
Joined: Tue Feb 28, 2006 9:11 pm
Location: Trondheim, Norway

Postby GreEn`mArine » Thu Mar 30, 2006 3:29 pm

however, the PHP code itself works fine. the generated html-code is exactly the way I wanted it

unfortunately setting the border attribute to "0" didn't help either.

Ah, I got it now:
cellpadding="2"
cellspacing="0"
IRC quote:
[kojn] I've been coming a bit more recently
[kojn] she took it the dirty way
GreEn`mArine
Forum addon
 
Posts: 1509
Joined: Tue Feb 28, 2006 9:33 pm
Location: Germany

Postby tChr » Thu Mar 30, 2006 3:31 pm

Hard to theorize without a screenshot. :)
the spice extend life!
the spice expand conciousness!
the spice is vital to space travel!
sooooo.. tell me what you want, waht you really-really want
I will proceed directly to the intravenous injection of hard drugs, please.
tChr
Forum addon
 
Posts: 1501
Joined: Tue Feb 28, 2006 9:11 pm
Location: Trondheim, Norway

Postby GreEn`mArine » Thu Mar 30, 2006 3:34 pm

Rankings page is updated :-)
IRC quote:
[kojn] I've been coming a bit more recently
[kojn] she took it the dirty way
GreEn`mArine
Forum addon
 
Posts: 1509
Joined: Tue Feb 28, 2006 9:33 pm
Location: Germany

PreviousNext

Return to Nexuiz Ladders - 1on1

Who is online

Users browsing this forum: No registered users and 1 guest

cron