Jump to content

New to HTML5 game development, advice appreciated


mugg
 Share

Recommended Posts

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

Link to comment
Share on other sites

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;  }}
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...