SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Game 2

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)

    Game 2

    Hi, I need help debugging this script:

    <script>
    function room1() {
    var command = document.former.command.value;
    var gotkey = document.hide.A1.value;
    var dooropen = document.hide.A2.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.stats.value="You are in a room. A key is to your left and a door infront."}
    {document.hide.A1.value="0"}
    {document.hide.A2.value="0"}
    if (command == "get key" && gotkey == "0") {document.former.info.value=x +"\n You got the key."} {document.former.inv.value=y +"\n key"} {document.hide.A1.value="1"} {document.former.stats.value="You are in a room. A door is infront of you"}
    else if (command == "get key" && gotkey == "1") {document.former.info.value=x +"\n There is no key anywhere in the area"}
    else if (command == "open door" && gotkey == "0") {document.former.info.value=x +"\n The door is locked"}
    else if (command == "open door" && gotkey == "1" && dooropen == "0") {document.former.info.value=x +"\n You opened the door!"} {document.hide.A2.value="1"}
    else if (command == "open door" && dooropen == "1") {document.former.info.value=x +"\n The door is already opened!"}
    else if (command == "go door" && dooropen == "1") {document.former.info.value=x +"\n You walk into the next room."}
    else if (command == "go door" && dooropen == "1") {document.former.info.value=x +"\n The door is locked."}
    </script>






    <form name="former">
    <input type="textarea" name="stats" value="Game Loaded!" 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="room1()" name="submit">
    <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">
    <input type="hidden" name="A5" value="0">
    <input type="hidden" name="A6" value="0">
    <input type="hidden" name="A7" value="0">
    <input type="hidden" name="A8" value="0">

    </form>

  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)

    New Script

    Please, I really need help on this:

    <script>
    function room1() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.hide.aa.value="0"}
    {document.hide.bb.value="0"}
    if ((command == "get key") && (gotkey == "0")) {room1A()}
    else if ((command == "get key") && (gotkey == "1")) {room1B()}
    else if ((command == "open door") && (gotkey == "0")) {room1C()}
    else if ((command == "open door") && (gotkey == "1") && (dooropen == "0")) {room1D()}
    else if ((command == "open door") && (dooropen == "1")) {room1E()}
    else if ((command == "go door") && (dooropen == "1")) {room1F()}
    else if ((command == "go door") && (dooropen == "1")) {room1G()}
    else {
    room1H()
    }
    }
    function room1A() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n You got the key"}
    {document.former.inv.value=y +"\n key}
    {document.hide.aa.value="1"}
    {document.former.stats.value="You are in a room. A door is infront of you"}
    }

    function room1B() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n There is no key anywhere in the area"}
    }

    function room1C() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n The door is locked"}
    }

    function room1D() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n You opened the door!"}
    {document.hide.bb.value="1"}
    }
    function room1E() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n The door is already opened!"}
    }
    function room1F() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n You walk into the next room."}
    }
    function room1G() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n The door is locked."}
    }
    function room1H() {
    var command = document.former.command.value;
    var gotkey = document.hide.aa.value;
    var dooropen = document.hide.bb.value;
    var x = document.former.info.value;
    var y = document.former.inv.value;
    {document.former.info.value=x +"\n Invalid Command"}

    }

    </script>






    <form name="former">
    <input type="textarea" name="stats" value="You are in a room. A key is to your left and a door infront." 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="room1()" name="submit">
    <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="aa" value="0">
    <input type="hidden" name="bb" value="0">


    </form>

  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)
    Instead of just saying that you need help say what your problem is, which line it's occuring on, and any other helpful information.

    Anyway, the way you've designed the script is not a good. Instead of using variables and individual functions you should be using objects with arrays. This is a fairly complex script; it would probably be better if you worked on smaller scripts until you get better at javascript.
    ck :: bringing chris to the masses.

  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)
    1. Line 27 Unterminated String Constant
    2. I don't know arrays
    3. I did start from easier scripts (password scripts, to scripts which close window/open on command, to another game similar to this, and then this harder game)

  5. #5
    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)
    Okay then look around line 27 and see what's wrong. For example:
    document.former.inv.value=y +"\n key}

    If you don't know arrays or objects then read some tutorials at sitepoint, webmonkey.com, and devshed.com
    ck :: bringing chris to the masses.

  6. #6
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Line 27 seems fine to me:

    {document.former.info.value=x +"\n You got the key"}

  7. #7
    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)
    Look at the lines around line 27, such as the one I already gave...
    ck :: bringing chris to the masses.

  8. #8
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But that line is correct {document.former.inv.value=y +"\n key}

  9. #9
    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)
    No, you need a closing quote...
    ck :: bringing chris to the masses.

  10. #10
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops! I guess I was blinded by my own frustration after sitting at the same script 8 hours straight.

  11. #11
    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 think I have gotten rid of all of the bugs. I now ask you to please try to locate any bugs, and post here if you find any. http://skullkillers.tripod.com/gametest.html
    Last edited by Disk-t; Jul 30, 2001 at 18:39.


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
  •