Forum Moderators: coopster

Message Too Old, No Replies

I can't stop the hammering!

multiple executions of script

         

bibby

5:42 am on Aug 23, 2005 (gmt 0)

10+ Year Member



I'm well on my way to a decent PHP RPG, and for tonight, I put together a battle system much like Final Fantasy and others.
Works like this...
Your party ( of 1 to 3) battles a monster mob (of 1 to 5), and each of the 2 to 8 participants has a 'dexterity value'. That dex value determines who gets to strike next after the current guy is finished, which works fine.

BUT_ here's the thing:
When it's your turn to attack, and all that you need is to pick a target ( an [a href]), you can hammer the link (or click it a bunch of times) and get many strikes out of a single turn!
The 'action' handler is a seperate .php, and the first thing it does is take the active character and move him down the list.

How can I stop this?!

I thought about switching the method to a form, but I remember seeing paysites that suggest that I click the submit button ONLY ONCE! Would this still happen with forms as well?

Should I bounce to an additional script?
hmmm might work, or would it?
(Selection.php --->
Location: KickYouAsActive.php?active=you --->
Location: Action.php --->
[back to]Location: Selection.php)

///////

raimondious

5:28 pm on Aug 24, 2005 (gmt 0)

10+ Year Member



Maybe use JavaScript to set a flag contained in a hidden input.
<input type="hidden" name="performedAction" value="false">

Then you would have
onmousedown="document.performedAction=true"
in your links and this would get sent to the next script so you could have

if(performedAction){//ignore}
else{ perform action}

chrisjoha

10:48 pm on Aug 24, 2005 (gmt 0)

10+ Year Member



Javascript is a good suggestion. But you could also extend the example to show the user that hammering is not allowed. Let's say you've got <p><a href="taketurn.php" onclick="disableLink(this);">Go!</a></p>

Then do:


disableLink(aEl) {
text = aEl.innerHTML;
parentEl = aEl.parentNode;
parentEl.removeChild(aEl);
parentEl.appendChild(document.createTextNode(text));
}

This will effectively disable the link after one click. Of course, the example is crude and not thouroughly tested, but it should provide the concept.

chrisjoha

6:15 am on Aug 25, 2005 (gmt 0)

10+ Year Member



excuse my type, you need to add the keyword "function" of course:

function disableLink(aEl) {
text = aEl.innerHTML;
parentEl = aEl.parentNode;
parentEl.removeChild(aEl);
parentEl.appendChild(document.createTextNode(text));
}

raimondious

1:53 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



That's a good idea since it involves no server-side processing at all. Then again you could always use both just in case (that if-statement won't affect speed at all really)...

DaButcher

10:49 am on Aug 26, 2005 (gmt 0)

10+ Year Member



if your game is based on mysql, you can have a table with "open moves".

eg. Only one open move at a time, and I guess they have to wait for a turn/tick.
if it's turn-based, it's very simple..

first you arrange who is first, second and third.
first clicks:
update table, set can_move = 0
update table, set can_move = 1 where player = second

ps.. this is psuedocode!