#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0

    Help outputting array into loop


    Hello

    I can't get my array 'shuffled9' to properly output into a while loop.

    The while loop displays card images concattenated with the number that should be outputted as per the shuffled9 array (I've alert-checked my numbers in the array, they are all showing up properly in the alert box. The final length of the array is 150, so all 150 numbers are in there.

    The problem is with my loop, which I'm not so good with yet. I get the an error when I click on a card "the value of 'cashcard_#<--random #' is null or undefined." All I want to do is concattinate the output number with 'cashcard_'.

    Here is code:
    Code:
    alert(shuffled9)// All numbers check out fine, they are all there
    
    //Start Card Placeholder Image (shows it is top of deck)
    document.write("<img src='new images/Cash_Card_Start.jpg' class='hand_cursor' width='41px' align='absmiddle' border='0' onClick='window.scrollBy(49,0)'>&nbsp;&nbsp;")
    
    //My feeble attempt at getting this while loop to work
    var current_card=0,len=shuffled9.length;
    
    alert(len)// length checks out properly at 150 cards (numbers seperated by commas)
    
    while (current_card<len){ 
    
    	document.write("<img src='new images/Cash_Card_Up.jpg' class='hand_cursor' onMouseOver='src=\"new images/Cash_Card_Over.jpg\";' onMouseDown='src=\"new images/Cash_Card_Down.jpg\";' onMouseOut='src=\"new images/Cash_Card_Up.jpg\";' onClick='cashcard_" + shuffled9[current_card++] + "(),window.scrollBy(49,0)' width='41px' align='absmiddle' border='0'>&nbsp;&nbsp;");
    	}
    
    //This is me ripping my hair out in frustration over this while loop
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    12
    Hi,

    I don't even get what you're trying to do. What is "cashcard_..." supposed to be? A string? A variable?

    Your current code assumes that cashcard_... is a function and calls it. But I'm pretty sure you don't have 150 function floating around in your code, and that's also what your browser is telling you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    24
    Rep Power
    0
    Code:
    for(var i = 0; i < len; i++){ 
    
    	document.write("<img src='new images/Cash_Card_Up.jpg' class='hand_cursor' onMouseOver='src=\"new images/Cash_Card_Over.jpg\";' onMouseDown='src=\"new images/Cash_Card_Down.jpg\";' onMouseOut='src=\"new images/Cash_Card_Up.jpg\";' onClick='cashcard_" + shuffled9[i] + "(),window.scrollBy(49,0)' width='41px' align='absmiddle' border='0'>&nbsp;&nbsp;");
    
    }
    Please notice that document.write will remove everything that is already on the page.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by Jacques3
    Hi,

    I don't even get what you're trying to do. What is "cashcard_..." supposed to be? A string? A variable?

    Your current code assumes that cashcard_... is a function and calls it. But I'm pretty sure you don't have 150 function floating around in your code, and that's also what your browser is telling you.
    Sorry, I haven't updated my coding skills in 10 years (not that I was ever really good at it. But good enough to create an Offline webpage that helps me playtest a boardgame I designed.

    The page has tonnes of cool tricks and is perfect for playtesting the game (the game is a cross between Risk & Monopoly, but on a much larger scale. Moreso intended for hardcore gamers. It makes the other two games, especially Monopoly, look like childrens drawings. I have tonnes of talent with art, especially computer art. I have a background in Cartography which helped alot too.

    I've been working on the game pretty steadily now for 5-6 years so it is quite polished. The game was made using Illustrator/Photoshop.

    And now the playtesting site is almost fully polished too.

    The cashcards I was refering to, is one of 3 decks for the game. Cash Cards, Cost Cards, and Travel Cards (think chance and community chest). There are 150 cards in each deck. !35 cards from each deck are 'collectable'. Therefor, each player (all 6) has a checklist to mark the cards they currently have in there collection. For different reasons, they can cash in these cards when certain sets have been obtained (Risk-like).

    So, on my page, I made an iframe for each deck. In that I frame is a page that has 150 cards (face-down) spread out in a line across the top of the page. Each card is clickable, so that a popup page appears showing the face-up side of the card. This cald-click also moves the the page in the iframe to the next card. This simulates a deck of cards. After the last card appears, there is a placeholder image that lets you know you`ve reach the end of the line of cards. Then you can click the 'shuffle button' to reload the page which checks the players card collections and wont populate the card arrays if the checkboxes are checked (card is owned).

    Hope that helps explaine what I'm attempting. I don't code for cash (yet) but know enough to have made a pretty cool offline site.

    If it ever goes online though, I'd need a real good coder to help me convert it for online viewing and usage.

    So I'll try the for-loop shown below, hopefully that works.

    Thanks Guys.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by leonvv
    Code:
    for(var i = 0; i < len; i++){ 
    
    	document.write("<img src='new images/Cash_Card_Up.jpg' class='hand_cursor' onMouseOver='src=\"new images/Cash_Card_Over.jpg\";' onMouseDown='src=\"new images/Cash_Card_Down.jpg\";' onMouseOut='src=\"new images/Cash_Card_Up.jpg\";' onClick='cashcard_" + shuffled9[i] + "(),window.scrollBy(49,0)' width='41px' align='absmiddle' border='0'>&nbsp;&nbsp;");
    
    }
    Please notice that document.write will remove everything that is already on the page.
    ok I tried the for-loop but when I click on a card. the corrosponding popup window (showing the card face-up) doesn't appear. My editor gives me this message:

    "The value of the property 'cashcard_88' (or other cards if reshuffled) is null or undefigned, not a function object'

    LOL ok I just found that the link to the remote js page with the functions was not on the page (i linked the wrong one)

    But, there seems to still be one problem. When the card popup opens, it looks fine, but IE either stops working, or I get this error message:

    res://ieframe.dll/acr_error.htm#,file:///J:/Play%20Travel%20Barons/Travel_Barons_Offline.html

    Any Ideas?

    Thanks

    PS Maybe the iframe page should be a js page, not an html page?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0
    OK, I've converted the iframe page to a js page.

    I think we're almost done. The only error I get now is that there should be a ';' on line 5314 character 224 inside the for loop (as im not posting the full code - too long - line 5314 is the forloop line).

    here is the new code:
    Code:
    var shuffled9 = shuffled8.sort( function() { return Math.random() - 0.4 } );
    
    
    //Start Card Placeholder Image (shows it is top of deck)
    document.write("<img src='new images/Cash_Card_Start.jpg' class='hand_cursor' width='41px' align='absmiddle' border='0' onClick='window.scrollBy(49,0)'>&nbsp;&nbsp;")
    
    //My feeble attempt at getting this while loop to work
    var current_card=0,len=shuffled9.length;
    alert(len)
    //This is me ripping my hair out in frustration over this while loop
    
    
    
    document.write("</head>")
    
    document.write("<body topmargin='0' leftmargin='0' bgcolor='#339933'>
    
    document.write("<table border='0' class='cash_card_footer' bordercolor='#339933' width='241pt' height='156pt' cellpadding='0' cellspacing='5'>")
    document.write("<tr valign='absmiddle'>")
    document.write("<td>")
    document.write("<img src='new images/Cash_Card_Start.jpg' class='hand_cursor' width='41px' align='absmiddle' border='0' onClick='window.scrollBy(49,0)'>&nbsp;&nbsp;")
    for(var i = 0; i < len; i++){ 
    
    	document.write("<img src='new images/Cash_Card_Up.jpg' class='hand_cursor' onMouseOver='new images/Cash_Card_Over.jpg' onMouseDown='new images/Cash_Card_Down.jpg' onMouseOut='new images/Cash_Card_Up.jpg' onClick='cashcard_" + shuffled9[i] + "(),window.scrollBy(49,0)' width='41px' align='absmiddle' border='0'>&nbsp;&nbsp;");
    
    }
    document.write("<img src='new images/Draw_Card_Reshuffle.jpg' class='hand_cursor' width='41px' align='absmiddle' border='0'>")
    document.write("</td>")
    document.write("</tr>")
    document.write("</table>")
    
    
    document.write("</body>")
    document.write("</html>")
    }
    Am I on the right track? I can't figure why there would be an expected ";" there.
  12. #7
  13. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,110
    Rep Power
    119
    You need to end each of your document.write() and your alert() with a semi-colon. You haven't done that, for most of them; so that is why you are getting the error(s). It also looks like you need to brush up on your JS; Google "Learn JavaScript" and go from there... that will help you more then anything.

IMN logo majestic logo threadwatch logo seochat tools logo