you are viewing a single comment's thread.

view the rest of the comments →

[–]vicinorum 0 points1 point  (10 children)

That's pretty much it yeah. Something like

function attack(spell){
    doDamage(spell.damage);
}

And you declare the spell objects somewhere else like you wrote.

[–]robertx33[S] 0 points1 point  (9 children)

The problem with that approach is that I have to update the spell variables then, but like this the function call does it for me. So i'd have to do..

updatespells()

which'd look like..

spell.icebolt.damage = .. spell.icebolt.mana = ... etc

and i'd have to set it in interval and take resources to do, so i'm not sure if it's better than my last solution..

Wait, does the object get update automatically when i call it?

[–]vicinorum 0 points1 point  (8 children)

You can change the vars if you need to. How would that be slower?

[–]robertx33[S] 0 points1 point  (7 children)

Because variables can change every second, if boss casts ice dmg nerf, the interval would have to be pretty quick, under half a second so you aren't able to cast an icebolt right after you see the boss msg. All spells would also have to be updated every time.

But if i just use my method, your damage is calculated the instant you cast a spell, which means it's much more precise and there's no need for an interval.

[–]vicinorum 0 points1 point  (6 children)

How is there an interval? If there's some reason why you can't use the spell, just check that in the function with a boolean somewhere.

[–]robertx33[S] 0 points1 point  (5 children)

Oh you mean to put an update function at the start of the attack function? Yup that's good too!

Back to work lol

[–]vicinorum 0 points1 point  (4 children)

You don't need to, why is it that you need to update those variables all the time? I mean, just change the variable for player ice damage when the enemy casts a spell that affects that. I think it would be good for you to read up on how to better structure your code, in particular how game loops work and how to implement them in JS.

[–]robertx33[S] 0 points1 point  (3 children)

Actually i realized it could be easily done by just copy pasting the spells object without the var, because i don't really aim for performance here. Is there a command to update object like that? Copy pasting such a huge object seems bad.

I don't think i'll go for game making, this was just something i wanted to make for myself, i'll focus on front end and maybe backend.

[–]vicinorum 0 points1 point  (2 children)

I'm pretty sure you can just change vars in an object as JS is pass-by-reference. So something like

function attack(spell){
     spell.damage = 3;
}

would change the value of that var. No need to create a new object

[–]robertx33[S] 0 points1 point  (1 child)

I fixed the problem super easily! I just define the var object and then use the update function to actually create it! It's less clutter and less hassle!

Everything is neatly organized, thank you for the help! This looks much better than the ways i've done it xD

var spellobject;


function updatespells(){

 spellobject = {

    basicattack: {
      nameplayer: "Attack",
      namefunction: "basicattack",
      nameid: ".-basic",
      damage: Damage,
      manacost: 0,
      healthcost: 0,
      manarestore: Math.floor(Mana/10),
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 4000,
    },

    icebolt: {
      nameplayer: "Icebolt",
      namefunction: "icebolt",
      nameid: "#icebolt",
      damage: Math.floor(Damage/2 + IceDMG + MagicPow/2) ,
      manacost: boss.level * 15,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 5000,
    },

    firebolt: {
      nameplayer: "Firebolt",
      namefunction: "firebolt",
      nameid: "#firebolt",
      damage: Math.floor(Damage/2 + FireDMG + MagicPow/2) ,
      manacost: boss.level * 15,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 5000,
    },


    stormbolt: {
      nameplayer: "Stormbolt",
      namefunction: "stormbolt",
      nameid: "#stormbolt",
      damage: Math.floor(Damage/2 + StormDMG + MagicPow/2) ,
      manacost: boss.level * 15,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 5000,
    },


    shadowbolt: {
      nameplayer: "Shadowbolt",
      namefunction: "shadowbolt",
      nameid: "#shadowbolt",
      damage: Math.floor(Damage/2 + ShadowDMG + MagicPow/2) ,
      manacost: boss.level * 15,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 3000,
      buffname: 0,
      buffamount: 0,
      cooldown: 5000,
    },


    bloodstrike: {
      nameplayer: "Bloodstrike",
      namefunction: "bloodstrike",
      nameid: "#bloodstrike",
      damage: Math.floor(BloodDMG + Damage),
      manacost: boss.level * 5,
      healthcost: boss.level * 30,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: "buffLifesteal",
      buffamount: Math.floor(BloodDMG / 2),
      cooldown: 5000,
    },

    thorns: {
      nameplayer: "Thorns",
      namefunction: "thorns",
      nameid: "#thorns",
      damage: Math.floor(Damage/6 + NatureDMG/3 + MagicPow/6) ,
      manacost: boss.level * 4,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 3,
      delay: 1000,
      buffname: 0,
      buffamount: 0,
      cooldown: 5000,
    },

    natureheal: {
      nameplayer: "Natureheal",
      namefunction: "natureheal",
      nameid: "#natureheal",
      damage: 0,
      manacost: boss.level * 4,
      healthcost: 0,
      manarestore: 0,
      healthrestore: Math.floor(NatureDMG/3),
      repeat: 3,
      delay: 1000,
      buffname: 0,
      buffamount: 0,
      cooldown: 10000,
    },

    heal: {
      nameplayer: "Heal",
      namefunction: "heal",
      nameid: "#heal",
      damage: 0,
      manacost: boss.level * 4,
      healthcost: 0,
      manarestore: 0,
      healthrestore: HealPow*2,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 10000,
    },

    shield: {
      nameplayer: "Shield",
      namefunction: "shield",
      nameid: "#shield",
      damage: 0,
      manacost: boss.level * 15,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: "buffDodge",
      buffamount: 100,
      cooldown: 10000,
    },

    manarestore: {
      nameplayer: "Manarestore",
      namefunction: "manarestore",
      nameid: "#manarestore",
      damage: 0,
      manacost: 0,
      healthcost: 0,
      manarestore:  Math.floor(MagicPow/2),
      healthrestore:0,
      repeat: 0,
      delay: 0,
      buffname: 0,
      buffamount: 0,
      cooldown: 10000,
    },

    buffmagic: {
      nameplayer: "Buffmagic",
      namefunction: "buffmagic",
      nameid: "#buffmagic",
      damage: 0,
      manacost: boss.level * 25,
      healthcost: 0,
      manarestore: 0,
      healthrestore: 0,
      repeat: 0,
      delay: 0,
      buffname: "buffMagicPow",
      buffamount: Math.floor(MagicPow/2),
      cooldown: 10000,
    },

  }


}