Quantcast
Channel: The Battle for Wesnoth Forums
Viewing all articles
Browse latest Browse all 2224

Lua Labs • Accuracy does not work

$
0
0
This code gets called whenever attack starts (to turn on) and ends (to turn off):

Code:

local function guarantee_hit(unit, guarantee)    for w =1, #unit.attacks do        if guarantee == true then            unit.attacks[w].accuracy = unit.attacks[w].accuracy + 100            wesnoth.interface.add_chat_message("attack accuracy start" .. unit.attacks[w].accuracy)                    else            unit.attacks[w].accuracy = unit.attacks[w].accuracy - 100            wesnoth.interface.add_chat_message("attack accuracy end " .. unit.attacks[w].accuracy)                    end    endend
The problem: During the attck, unit will still use their normal accuracy, meaning they miss attacks, AND after the attack it says on their weapon "-100%", so they can not hit anything.
The intention is that the code guarantees hits by turning it up by 100, then back to normal after the attack.

It would seem like this line is never run..

Code:

unit.attacks[w].accuracy = unit.attacks[w].accuracy + 100
But when I print the variable after this is run, accuracy is 100.

So what is going on? It seems like the variable is not saved onto the unit if it runs from the attack event.

Statistics: Posted by B099 — Yesterday, 6:47 pm



Viewing all articles
Browse latest Browse all 2224

Trending Articles