http://eloquentjavascript.net/
On Sat, Aug 4, 2012 at 11:40 AM, Brian Stahly <[email protected]>wrote: > I am trying to build a small, online card game with NodeJS. Having C# and > javascript experience, I am having way more trouble than I expected. > > Using node-static, I set up an http server (server.js) that successfully > serves client.html and any requested assets. > I am starting to build the basics of the card game using the CraftyJS > library in client.js (running on the client.html page). > Using Socket.io, I can successfully send information from server.js to my > client.js file. > > My next step was to generate an array of cards in server.js, splice one > out randomly, and send it to client.js. My hope was: > > var deck = new Array(); > deck.push(new Array("card1 info", "more info")); > deck.push(new Array("card 2 info", "more info")); > deck.push(new Array("card 3 info", "more info")); > > function drawCard(){ > return deck.splice(1,1); > } > > I've spent the whole day reading, but I can't find a clear concise answer. > Question 1: Why doesn't this work? The V8 compiler sees arrays as string > values? This is not the javascript I know, is there a tutorial for this new > way of dealing with arrays? > > After more reading, I got it working a this way: > var deck = []; > deck[0] = {info:"test", moreInfo:"test"}; > deck[1] = {info:"test", moreInfo:"test"}; > deck[2] = {info:"test", moreInfo:"test"}; > > However: > console.log(deck[0]) yields {info: 'test', moreInfo:'test'} > console.log(deck.splice(0,1)) yields *[*{info: 'test', moreInfo:'test'}*]* > * > * > Question 2: Why does splice return the square brackets, but calling the > value directly does not? > > Any answers or additional links are really appreciated. When I search for > javascript help, I end up on HTML javascript pages, which obviously doesn't > work as I expect. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
