Stop a script using javascript...

This is for an opera widget

Page 1 of 1

2 Replies - 10937 Views - Last Post: 24 March 2007 - 01:25 PM

#1 smartboyathome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-October 06

Stop a script using javascript...

Posted 22 March 2007 - 02:30 PM

I am making a chess widget right now for opera. I am trying to make a mode where if a player selects 2 from the number of players drop down menu, the index.html file will stop processing the chess_6k.js application and will continue with the rest of the code. My hope is that I will be able to make a mode where the player can enter their moves without the computer, and then will be able to play from a point where they want to by selecting 1 again.

Also, I am trying to make a section of script that has my chess engine play itself. I don't know where to start, so does anyone have any pointers?

Lastly, here is my current code:

index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>
<title>Chess+</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<link rel="stylesheet" href="chess_6k.css" type="text/css" />


<script src="fancy_chess_6k.js" type="text/javascript">

</script>


</head>


<body onload="H()">

<table border="0" bgcolor=transparent align="right">
<button id="reload" class="reload all_buttons" onclick="reloadPage()" />
<button class="close all_buttons" onmouseup="window.close()" />
</table>
<br><br>
<form name="FF" method="post" action="index.html">

<table border="0" cellspacing="2" align="bottom left" class="mainTable">
<tbody>

<tr>

<td colspan="2" class="controlBar controlBarUpper">

<table width="100%">
<tr>
<td class="buttonBarUpper">

   
<button onclick="Gb(); return false;">
 undo 
</button>
      
<button onclick="Rf(8-P); return false;">
 swap 
</button>
      
Number of players:
<select id="player_number">
<option value="2">2</option>
<option selected="selected">1</option>
</select>
</td>

<td>
</td>

</tr>
</table>

</td>

</tr>

<tr>
<td>

<script src="chess_6k.js" id="chessCss">
</script>

</td>

<td>

<textarea name="b" cols="12" rows="18">
</textarea>

</td>

</tr>

<tr>

<td colspan="2" class="controlBar controlBarBottom">

Next pawn becomes:

<select name="h">

<option selected>queen</option>

<option>bishop</option>

<option>knight</option>

<option>rook</option>

</select>
Computer level:
<select name="i">
<option>stupid</option>

<option selected>middling</option>
<option>slow</option>
</select>
</td>
</tr>
</tbody>
</table>
</form>
<br/>
<table id="tableAbout" width="460" align="center">
<tbody>
<tr>
<td align="left" id="aboutCell">
<p>
<strong>P4wn</strong> is Javascript chess written by Douglas Bagnall. Original website can be found here:
<a href="http://p4wn.sourceforge.net/">http://p4wn.sourceforge.net/</a>.
</p>
<p>
This version is 6K engine with new graphics for better readability and respective code changes.
</p>
<p>
<strong>Notes</strong>
</p>
<ul>
<li>Castling is done by moving the king, rook moves automatically.</li>
<li>When swapping sides computer makes its move instantly (since it's its turn) so you may be disoriented at first and not notice it.</li>
<li>May be slow/jerky with some browsers/computers</li>
</ul>
<p align="right">

<a href="mailto:aabram@gmail.com" title="e-mail">
aab
</a>
</p>
</td>

</tr>

</tbody>

</table>

</body>

</html>



fancy_chess_6k.js:
// ***************************
// 6k chess
// custom functions go here
// ***************************

function about() {
	if(document.getElementById('tableAbout').style.display == 'block') {
		document.getElementById('tableAbout').style.display = 'none';
	}else{
		document.getElementById('tableAbout').style.display = 'block';
	}
};


function reloadPage()
   {
   window.location.reload()
   }

if (player_number == 2)
{
document.getElementById("chessCss")
defer
}


This post has been edited by smartboyathome: 22 March 2007 - 02:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Stop a script using javascript...

#2 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Stop a script using javascript...

Posted 24 March 2007 - 01:22 PM

Have you considered using a While loop?
while (player_number==1)
{
	code to be executed
}


Just some food for thought ...


This post has been edited by DilutedImage: 24 March 2007 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 smartboyathome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-October 06

Re: Stop a script using javascript...

Posted 24 March 2007 - 01:25 PM

View PostDilutedImage, on 24 Mar, 2007 - 01:22 PM, said:

Have you considered using a While loop?
while (player_number==1)
{
	code to be executed
}


Just some food for thought ...



Thanks, just wondering, if I use this, is there any way to call the script?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1