Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post

    array driving me mad!

    This is driving me maaaaaaad and I dont know why it's not working!!

    I set up an array when the page loads eg:

    Code:
    backup = new Array();
    backup[0] = "testing";
    then I have a function called undo() which tries to add a value to the array... only it cant be accessed. When I test the length of backup, it says it's ZERO... when you can clearly see I've put an item in it above!!

    how come I cant access it? My functions are in an included .JS file maybe that's why?!

    BTW: this is a modified version of axinya's undo-redo function which seems to work perfectly!! (http://www.codingforums.com/showthread.php?t=39987)

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow will need to be a global

    you might need to declare it as global, like so:

    Code:
    var backup = new Array();

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Variables are automatically turned to global scope if the var keyword is not specified. Though it's a good practice to always put it.

    homerUK, can you post more codes? Maybe you are re-initializing it somewhere.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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