Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Code Not Running as it should
Old 10-14-2010, 04:53 AM Code Not Running as it should
Banned

Posts: 408
Name: mushget
Trades: 0
The first time I enter the command n it should run the first if statement, when I enter n it should then run the second one as its in zone two. However this is just not happening... What am I doing wrong. Its simply running the second one and skipping the first. Thanks in advance folks

Code:
// gameFunctions.js 
// Javascript file for Game.html
// September 29th 2010 Edition


// The below represent our global variables for the game. The first variable 
// is called playerScore, and represents the total earned points. The player 
// earns or loses points based on progress in the game, this value can either 
// increase or decrease. 

var playerLocation = "zone";

function runProgram()
{
var command = "";
command = document.getElementById("txtCommand").value;
switch (command)
{
case "n": north();
break;
case "s": south(); 
break;
case "e": east();
break;
case "w": west();
break;
case "north": north();
break;
case "south": south(); 
break;
case "east": east();
break;
case "west": west();
break;
default: giveError();
}
}

// The following function when called will take the player north.

function north()
{
if(playerLocation = "zone")
{
var message = "You have come to what seems to be a beach";
post(message);
var playerLocation = "zoneTwo";
}
if(playerLocation = "zoneTwo")
{
var message = "You are unsure if you should set up camp. Set up camp?"
post(message);
var playerLocation = "zoneThree";
}
else
{
giveError();
}
}

// The following function when called will take the player east.

function east()
{
if(playerLocation = "zone")
{
var message = "You have come to a very large and steep mountain";
post(message);
var playerLocation = "zoneTwo";
}
if(playerLocation = "zoneTwo")
{
var message = "You are unsure if you should set up camp. Set up Camp?";
post(message);
var playerLocation = "zoneThree";
}
else
{
giveError();
}
}

// The following function when called will take the player south.

function south()
{
if(playerLocation = "zone")
{
var message = "You have come to the entrance of a mine";
post(message);
var playerLocation = "zoneTwo";
}
if(playerLocation = "zoneTwo")
{
var message = "You are unsure if you should set up camp. Set up Camp?";
post(message);
var playerLocation = "zoneThree";
}
else
{
giveError();
}
}

}

// The following function when called will take the player west.

function west()
{
if(playerLocation = "zone")
{
var message = "You have found the edge of the world";
post(message);
var playerLocation = "zoneTwo";
}
if(playerLocation = "zoneTwo")
{
var message = "You are unsure if you should set up camp. Set up Camp?";
post(message);
var playerLocation = "zoneThree";
}
else
{
giveError();
}
}

// The following function reports an error when the program deviates from standard functionality. It is used mainly for debugging.

function giveError()
{
alert("gameFunctions.js has encountered a critical error")
alert("Please check that you are not using Internet Explorer to run this page")
alert("The program will now close")
}

// The following function reports an error when the typed in command is not recognized by the program database.

function doNotUnderstand()
{
alert("I am sorry but I do not understand please try again") 
}

function post(newText)
{
document.getElementById("taGameText").value = ""
var gameTextBox = document.getElementById("taGameText");
gameTextBox.value = newText + gameTextBox.value;
}

Last edited by chrishirst; 10-14-2010 at 06:46 PM..
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
 
Register now for full access!
Old 10-14-2010, 05:32 PM Re: Code Not Running as it should
siteion's Avatar
Average Talker

Posts: 20
Trades: 0
You should use == instead of one = in string comparison
does that help?
__________________
Track website visitors with
Please login or register to view this content. Registration is FREE
, easy to install.
siteion is offline
Reply With Quote
View Public Profile Visit siteion's homepage!
 
Old 10-16-2010, 09:31 AM Re: Code Not Running as it should
siteion's Avatar
Average Talker

Posts: 20
Trades: 0
And have you tried it?
__________________
Track website visitors with
Please login or register to view this content. Registration is FREE
, easy to install.
siteion is offline
Reply With Quote
View Public Profile Visit siteion's homepage!
 
Reply     « Reply to Code Not Running as it should
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14909 seconds with 12 queries