Page 1 of 2
Button Question for php
Posted: Thu Sep 10, 2009 8:36 am
by dave3460
HI Guys just have a question about a click button i am using for a game i am making.
Works the same way as hall,s forsaken attack button.
what i want to do is make the button loop so when your press it .it will just go through fight process till you or the creatures die,s so you dont have to keep pressing fight again .you will be able to eat so you can reheal during fights.
just not 100% sure do i use a loop or some other piece of codes
Re: Button Question for php
Posted: Thu Sep 10, 2009 11:10 am
by Jackolantern
Without knowing exactly what you are wanting to do, here is likely how you would want to do a fight loop:
Code: Select all
do {
//fight code
//fight code
} while (monster != dead && player !=dead)
Of course you may have to exchange the end references depending on how player and monster death work, but that is the loop. A "Do-While" loop is guaranteed to execute at least once, whereas a "While" loop is not.
Re: Button Question for php
Posted: Thu Sep 10, 2009 4:36 pm
by hallsofvallhalla
i would use functions instead
psuedo code
button="attack" onclick="playerattack()"
function playerattack()
{
attack code goes here
then at the end
if (creaturehp > 0)
{
creatureattack()
}
}
function creature attack()
{
attack code goes here
then at the end
if (playerhp > 0)
{
playerattack()
}
}
but remember this will go super fast so you need to add in a delay or sleep function between each attack.
Re: Button Question for php
Posted: Thu Sep 10, 2009 5:24 pm
by dave3460
I understand the delay function but what is a sleep function?
I think you guys just add functions to confuse me well it doesnt take much
Re: Button Question for php
Posted: Fri Sep 11, 2009 1:00 am
by hallsofvallhalla
delay is all you would need
Re: Button Question for php
Posted: Thu Sep 17, 2009 12:33 am
by mrmajic
can you please give an example containing the 'delay' code..
thanks.
Re: Button Question for php
Posted: Thu Sep 17, 2009 1:55 am
by hallsofvallhalla
i am sorry i meant sleep()
getting my coding languages confused
http://www.php.net/manual/en/function.sleep.php
sleep(5);
Re: Button Question for php
Posted: Thu Sep 17, 2009 10:51 am
by Jackolantern
hallsofvallhalla wrote:i would use functions instead
psuedo code
button="attack" onclick="playerattack()"
function playerattack()
{
attack code goes here
then at the end
if (creaturehp > 0)
{
creatureattack()
}
}
function creature attack()
{
attack code goes here
then at the end
if (playerhp > 0)
{
playerattack()
}
}
but remember this will go super fast so you need to add in a delay or sleep function between each attack.
Wouldn't the function calls take up more server resources than a loop?
Re: Button Question for php
Posted: Thu Sep 17, 2009 12:51 pm
by Falken
Wouldn't it be posisble to calculate the whole fight first in the php, then just let a javascript present it nicely?
Would save alot of power.
Re: Button Question for php
Posted: Thu Sep 17, 2009 2:07 pm
by hallsofvallhalla
Falken wrote:Wouldn't it be posisble to calculate the whole fight first in the php, then just let a javascript present it nicely?
Would save alot of power.
that is actually the way I do it Falken. I need to get my first video of my javascript tutorials out.
@Jack
I wouldn't think so. At least not enough to affect anything. Depending how you run your battle the functions would use less because they can be run at anytime and a loop would have to be written over and over. I am not going to lie, I really don't know the answer to that but I would assume it wouldn't be enough to even see or feel the difference.