Button Question for php

C++, C#, Java, PHP, ect...
dave3460
Posts: 117
Joined: Wed Jul 01, 2009 2:13 pm

Button Question for php

Post 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
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Button Question for php

Post 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.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Button Question for php

Post 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.
dave3460
Posts: 117
Joined: Wed Jul 01, 2009 2:13 pm

Re: Button Question for php

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Button Question for php

Post by hallsofvallhalla »

delay is all you would need
mrmajic
Posts: 117
Joined: Sat Jun 27, 2009 9:37 am

Re: Button Question for php

Post by mrmajic »

can you please give an example containing the 'delay' code..

thanks.
Mr Majic...

Current Project: http://www.deltarealm.net
feedback welcome.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Button Question for php

Post by hallsofvallhalla »

i am sorry i meant sleep()


getting my coding languages confused

http://www.php.net/manual/en/function.sleep.php

sleep(5);
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Button Question for php

Post 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?
The indelible lord of tl;dr
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Button Question for php

Post 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.
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Button Question for php

Post 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.
Post Reply

Return to “Coding”