id need to see the code to help more, where is currentTargets getting assigned, is there any loop that its nested inside, and wheres thr function call being used.
Viewing post in HP is not decreasing and effect animations are not working
Heres the code of obj_Batlle:
instance_deactivate_all(true)
units = []
turn = 0
unitTurnOrder = []
unitRenderOrder = []
turnCount = 0
roundCount = 0
battleWaitTimeFrames = 30
battleWaitTimeRemaining = 0
currentUser = noone
currentAction = -1
currentTargets = noone
for (var i = 0; i < array_length(enemies); i++)
{
enemyUnits[i] = instance_create_depth(x+300+(i*10), y+100+(i*20), depth-10, obj_BattleUnitEnemy, enemies[i])
array_push(units, enemyUnits[i])
}
for (var i = 0; i < array_length(global.party); i++)
{
partyUnits[i] = instance_create_depth(x+100+(i*10), y+100+(i*15), depth-10, obj_BattleUnitPC, global.party[i])
array_push(units, partyUnits[i])
/*partyUnits[i] = instance_create_depth(x-60+(i*10), y+(i*15), depth-10, obj_BattleUnitPC, global.party[i])
array_push(units, partyUnits[i])*/
}
unitTurnOrder = array_shuffle(units)
RefreshRenderOrder = function()
{
unitRenderOrder = []
array_copy(unitRenderOrder, 0, units, 0, array_length(units));
array_sort(unitRenderOrder, function(_1, _2)
{
return _1.y - _2.y;
})
}
RefreshRenderOrder()
function BattleStateSelectAction()
{
var _unit = unitTurnOrder[turn]
if (!instance_exists(_unit)) || (_unit.hp <= 0)
{
battleState = BattleStateVictoryCheck;
exit;
}
BeginAction(_unit.id, global.ActionLibrary.attack, _unit.id);
}
function BeginAction(_user, _action, _targets)
{
currentUser = _user
curentAction = _action
currentTargets = _targets
if (!is_array(_targets)) _targets = [_targets]
battleWaitTimeRemaining = battleWaitTimeFrames
with (_user)
{
acting = true
if (!is_undefined(_action[$ "userAnimation"])) && (!is_undefined(_user.sprites[$ _action.userAnimation]))
{
sprite_index = sprites[$ _action.userAnimation]
image_index = 0
}
}
battleState = BattleStatePerformAction
}
function BattleStatePerformAction()
{
if currentUser.acting
{
if currentUser.image_index >= currentUser.image_number -1
{
with currentUser
{
sprite_index = sprites.idle
image_index = 0
acting = false
}
if (variable_struct_exists(currentAction, "effectSprite"))
{
if (currentAction.effectOnTarget == MODE.ALWAYS) || ( (currentAction.effectOnTarget == MODE.VARIES) && (array_length(currentTargets) <= 1 ) )
{
for (var i = 0; i < array_length(currentTargets); i++)
{
instance_create_depth(currentTargets[i].x,currentTargets[i].y,currentTargets[i].depth-1,obj_BattleEffect,{sprite_index : currentAction.effectSprite})
}
}
else
{
var _effectSprite = currentAction.effectSprite
if (variable_struct_exists(currentAction, "effectSpriteNoTarget")) _effectSprite = currentAction.effectSpriteNoTarget;
instance_create_depth(x,y,depth-100,obj_BattleEffect,{sprite_index : _effectSprite});
}
}
currentAction.func(currentUser, currentTargets);
}
}
else
{
if (!instance_exists(obj_BattleEffect))
{
battleWaitTimeRemaining--
if (battleWaitTimeRemaining == 0)
{
battleState = BattleStateVictoryCheck;
}
}
}
}
function BattleStateVictoryCheck()
{
battleState = BattleStateTurnProgression
}
function BattleStateTurnProgression()
{
turnCount++
turn++
if (turn > array_length(unitTurnOrder) -1)
{
turn = 0
roundCount++
}
battleState = BattleStateSelectAction
}
battleState = BattleStateSelectAction
*this is the error you have now:
- curentAction = _action needs to be changed to currentAction= _action (You didnt spell then the same)
some changes from the code I have are (not needed to change):
- In the statement if (!is_array(_targets)) _targets = [_targets] _targets should be currentTargets ex: if (!is_array(currentTargets)) currentTargets = [currentTargets];
- At the line instance_create_depth(currentTargets[i].x,currentTargets[i].y,currentTargets[i].depth-1,obj_BattleEffect,{sprite_index : currentAction.effectSprite}) obj_BattleEffect is renamed from oBattleEffect just make sure its consistent with your naming.