Damage over time problem

running my DOT function to node

auto seq1 = Sequence::create(
CallFuncN::create(CC_CALLBACK_0(HelloWorld::burning, this, spawnedMonster_hp, monster_current_dmgDot.at(node->getTag()), node,spawnedMonster_node_vec)),
DelayTime::create(1.0f),
nullptr);
auto repeat1 = RepeatForever::create(seq1);
repeat1->setTag(BURNING);
node->runAction(repeat1);

my DOT function/method

void HelloWorld::burning(std::vector &monster_hp, int dmg, Node * node, Vector<Node*> *(&vecA))
{
int hp_current = monster_hp.at(node->getTag());
hp_current -= dmg;
monster_hp.at(node->getTag()) = hp_current;
log(“monster_hp.at(node->getTag()) -= dmg; %d”, monster_hp.at(node->getTag()));
prompt_dmg_label(int(dmg), node, Color3B::MAGENTA);
if (monster_hp.at(node->getTag()) < 1)
{
death(node, vecA);
}
}

Is actually decreasing, when logging.

log("monster_hp.at(node->getTag()) -= dmg; %d", monster_hp.at(node->getTag())); 

but after repeat1 is over node’s hp goes back.

I tried your code. To be able to use I reduced it to

    std::vector<int> thing; // I can't make this work using only std::vector with <int> included
    thing.push_back(100);

    auto seq1 = Sequence::create(
        CallFuncN::create(CC_CALLBACK_0(HelloWorld::burning, this, thing)),
        DelayTime::create(1.0f),
        nullptr);
    auto repeat1 = RepeatForever::create(seq1);
    runAction(repeat1);

and

void HelloWorld::burning(std::vector<int> &monster_hp)
{
    int hp = monster_hp.at(0);
    hp -= 5;
    monster_hp.at(0) = hp;
    
    CCLOG("HP: %d", monster_hp.at(0));
}

This code started with the number 100 in monster_hp and each time the action repeated, it went down by 5. So I can’t see any problems with this code.

Are you sure you aren’t accidentally resetting the monster HP in code somewhere else?

Hello grim, thank you. Here’s what i did.

I changed

std::vector monster_hp to std::vector *monster_hp

added monster_hp = new std::vector ;

and replace all instances of “.” monster_hp to “->”