mugg Posted February 19, 2015 Author Share Posted February 19, 2015 Really simple: testfunction = function() {};array = [];array.push(testfunction());// is testfunction in the array now?if (array[0] === testfunction()) console.log("success?");According to my test, the above example should fail to work. testfunction() is being executed instead of compared against, I think. More into detail: ailments = { burned : function (victim) { // code }, poisoned : function (victim) { // code } }; hero = { ... ailments: [], ... } hero.ailments.push(ailments.poisoned(hero)); hero.ailments.push(ailments.slowed(hero)); // now how do I find out if poisoned or if slowed are already in hero's ailments array? for (var i = 0; i < hero.ailments.length; i++) { if (hero.ailments===ailments.slowed(hero)) { // this check seems to not work? console.log("hello anyone?") } } --- edit:That seems like a good solution, thanks!v Quote Link to comment Share on other sites More sharing options...
AzraelTycka Posted February 19, 2015 Share Posted February 19, 2015 After pasting your code into fiddle I got a succes. In your code you call your function that obviously leads to its execution, if you don't want teh function to execute then stop calling it. Isn't your comparation itself written in a strange way? This condition "if (array[0] === testfunction())" says this: get zero position value of array, execute function testfunction and compare the resulting value with array's value. Can't you just set your if (switch) tree for different disables fo your hero straight? Simple list should be way faster in this case, or why exactly do you need to call the function to proceed all the time (this way it seems they you are just losing computation time for nothing - something that could be done in simplified way). example:hero = { disables: []};for (var i = 0; i < hero.disables.length; i++) { switch (hero.disables[i]) { case 'poisoned': // do something break; case 'frozen' // do something break; }} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.