Jump to content

output trouble (buttons)


the 7th Hokage

Recommended Posts

i have a function that works... well kind of.

 

i have it set that it runs on click. it utilizes some ajax and javascript to print php to the page without refreshing.

 

the problem is when i click the button the same output shows up each time.

 

what i want is the number to decrease and the new value to be available

 

this is the actual code

 

function smack($target)
{
$dmg=$this->ATT-=$target->DEF;//amount of HP loss
$newHP=$target->HP-=$dmg;// HP after dmg
echo $target->HP." hit points remaining.";
$target->HP=$newHp;

}

 

this is what it outputs

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .87 hit points remaining.

this is what i would like it to say

 

This is only a test.100 .87 hit points remaining.

 

This is only a test.100 .74 hit points remaining.

 

This is only a test.100 .61 hit points remaining.

... and so on

 

note that this is outputted to the page on button press. with ajax to write to the page without refreshing. I'm not sure if that's the cause of this or not. any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/171897-output-trouble-buttons/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.