Button Question for php
Button Question for php
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
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
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Button Question for php
Without knowing exactly what you are wanting to do, here is likely how you would want to do a fight loop:
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.
Code: Select all
do {
//fight code
//fight code
} while (monster != dead && player !=dead)
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Button Question for php
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.
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
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
I think you guys just add functions to confuse me well it doesnt take much
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Button Question for php
delay is all you would need
Re: Button Question for php
can you please give an example containing the 'delay' code..
thanks.
thanks.
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Button Question for php
i am sorry i meant sleep()
getting my coding languages confused
http://www.php.net/manual/en/function.sleep.php
sleep(5);
getting my coding languages confused
http://www.php.net/manual/en/function.sleep.php
sleep(5);
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Button Question for php
Wouldn't the function calls take up more server resources than a loop?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.
The indelible lord of tl;dr
Re: Button Question for php
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.
Would save alot of power.
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Button Question for php
that is actually the way I do it Falken. I need to get my first video of my javascript tutorials out.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.
@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.