SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: JS game

Hybrid View

  1. #1
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS game

    <script>
    function getit() {

    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var gotkey = "0";


    if (command == "get key" && gotkey == "0") {getkey()}

    else if (command == "get key" && gotkey == "1") {getkey1()}
    else {
    document.former.info.value=x +"\n Invalid Command"}

    function getkey() {
    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var gotkey = "1";
    {document.former.info.value=x + "\n You got the key"}
    }
    function getkey1() {
    document.former.info.value=x +"\n You already have the key"
    }
    }
    </script>

    <form name="former">
    <input type="textarea" name="stats" value="You are in a room. There is a key on the desk near you." size="84" onFocus="alert('You cannot edit this section!')">
    <p>
    <textarea rows="12" name="info" cols="52" onFocus="alert('You cannot edit this section!')"></textarea>
    </p>
    <p>
    <input type="text" name="command" size="20">
    </p>
    <p>
    <input type="button" value="Submit" onClick="getit()" name="B2">
    </form></p>

  2. #2
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yea, I need it debugged because it skips some of the commands.

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing that you said cannot because you couldn't get "can't" to work. You need to escape the apostrophe like so: can\'t.

    var gotkey = "0"; should be placed outside of the getit() function.

    var gotkey = "1"; should be gotkey = "1";

    {document.former.info.value=x + "\n You got the key"}
    should have the braces take off.

  4. #4
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyway, I've taken a new approach to it:

    <script>
    function getit() {

    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var inventory = document.former.inv.value;
    var check = document.hide.A1.value;
    if (command == "get key" && check == "0") {getkey()}
    else if (command == "open door" && check == "1") {getdoor1()}
    else if (command == "open door" && check == "1") {getdoor()}
    else if (command == "get key" && check == "0") {get key1()}
    else {
    document.former.info.value=x +"\n Invalid Command"}

    function getkey() {
    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var inventory = document.former.inv.value;
    var y = document.former.inv.value;
    var check = document.hide.A1.value;
    {document.former.info.value=x + "\n You got the key"}
    {document.former.inv.value=y + "\n Key"}
    {document.hide.A1.value="1"}
    }
    function getkey1() {
    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var inventory = document.former.inv.value;
    var check = document.hide.A1.value;
    document.former.info.value=x +"\n You already have the key"
    }
    function getdoor1() {
    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var inventory = document.former.inv.value;
    var check = document.hide.A1.value;
    document.former.info.value=x +"\n The door is locked and you are unable to open it"
    }
    function getdoor() {
    var stats = document.former.stats.value;
    var info = document.former.info.value;
    var command = document.former.command.value;
    var x = document.former.info.value;
    var inventory = document.former.inv.value;
    var check = document.hide.A1.value;
    document.former.info.value=x +"\n You have completed the mission!", window.close
    }
    }
    </script>

    <form name="former">
    <input type="textarea" name="stats" value="You are in a room. There is a key on the desk near you and a door in front of you." size="84" onFocus="this.blur()">
    <p>
    <textarea rows="12" name="info" cols="52" onFocus="this.blur()"></textarea>
    </p>
    <p>
    <input type="text" name="command" size="20">
    </p>
    <p>
    <input type="button" value="Submit" onClick="getit()" name="B2">
    <p><font color="#FF0000" size="4">Inventory</font>
    <p>
    <textarea rows="4" name="inv" value="Shoes" cols="29" onFocus="this.blur()"></textarea></form>
    </form>
    <form name="hide">
    <input type="hidden" name="A1" value="0">
    <input type="hidden" name="A2" value="0">
    <input type="hidden" name="A3" value="0">
    <input type="hidden" name="A4" value="0">
    </form>

  5. #5
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind! I already fixed it!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •