Jump to content

[SOLVED] [Q]PHP syntax


Minase

Recommended Posts

hy there im having an issue with a syntax,dont know where the error is :o (its more like a math problem,but its not that complex and it should be here)

 

$attacker->Dexterity = 100;
$defender->Dexterity = 150;
$dodge = $attacker->Dexterity - $defender->Dexterity;
if ($dodge < 1) {
$dodge = 0;
}

 

it seem that the dodge variable has no content after IF .

weird enough...

at first i though it was a math problem,but when i did write this topic i did check where the error was,and i did find that dodge variable disapear after IF.

thanks

Link to comment
Share on other sites

I think it's a small typing error on your part, or a minor logic flaw. Echo all expected values before attempting to compare them to make sure they're what you expect. Also check spelling and case on variables... they shouldn't just unset themselves.

 

error_reporting( E_ALL ); at the top of your script might help.

Link to comment
Share on other sites

thanks for reply but i already did that,no success  >:(

 

here is something interesting that i found

 

$attacker->Dexterity is set everything is fine but after this part it is unset...

 

$rounds1 = rand(5,10);
for($r = 1; $r <= $rounds1 ; $r++){

//  DEFENDER ATTACK
if ($r % 2 == 0) {
$dodge = $attacker->Dexterity - $defender->Dexterity;

after the

if ($r % 2 == 0) {

the variables stop to work..

but when it come

} else {
$dodge = $defender->Dexterity - $attacker->Dexterity;
....
}

it work normally  ???

Link to comment
Share on other sites

as disco said, turn your error reporting on.  I think the more likely thing is that  $attacker and/or $defender is not being instantiated somehow or maybe they are not within the scope of that script there (not passed to a function, etc...) so it's ending up basically saying $dodge = 0 - 0; or even $dodge = 0 - 100; causing the if to evaluate as true.   Just a thought.  Try echoing out $attacker->dexterity and $defender->dexterity after you set them.

Link to comment
Share on other sites

sorry for 2 post,but i want someone please to test this code

 

$rounds1 = rand(5,10);
for($r = 1; $r <= $rounds1; $r++){

//  DEFENDER ATTACK
if ($r % 2 == 0) {
$dodge = $attacker->Dexterity - $defender->Dexterity;
if ($dodge < 1) {
$dodge = 0;
}

$r = rand(0, 99);
$dc1 = ($r < $dodge) ? 1 : 0;
echo "DC1 :",$dc1;

// ATTACKER ATTACK
} else {
$dodge = $defender->Dexterity - $attacker->Dexterity;
if ($dodge < 1) {
$dodge = 0;
}

$r = rand(0, 99);
$dc2 = ($r < $dodge) ? 1 : 0;
echo "DC2 :",$dc2;

}
}

 

from my knowledge it should return

DC1: VALUE

DC2: VALUE

on my server it wont return those 2 values... weird enough...

 

thank you very much

Link to comment
Share on other sites

*sigh*

 

You redefine $r in your loop, and it screws things up. You should be able to catch this kind of stuff on your own.

 

<pre><?php

class someClass {
public $Dexterity;
}

$attacker = $defender = new someClass;
$attacker->Dexterity = 250;
$defender->Dexterity = 402;

$rounds1 = rand(2,5)*2;
for($r = 1; $r <= $rounds1; $r++){

//  DEFENDER ATTACK
if ($r % 2 == 0) {
	$dodge = $attacker->Dexterity - $defender->Dexterity;
	if ($dodge < 1) {
		$dodge = 0;
	}

	$r2 = rand(0, 99);
	$dc1 = ($r2 < $dodge) ? 1 : 0;
	echo "DC1 :$dc1\n";

// ATTACKER ATTACK
} else {
	$dodge = $defender->Dexterity - $attacker->Dexterity;
	if ($dodge < 1) {
		$dodge = 0;
	}

	$r2 = rand(0, 99);
	$dc2 = ($r2 < $dodge) ? 1 : 0;
	echo "DC2 :$dc2\n";

}
}

?></pre>

 

I really don't understand your algorithm.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.