Hello my dear reader!
Here I am again, requesting any help from anybody that could help me (huh... isn't that obvious?)
Welp, let's sink into the issue in this very insta:
Suppose we test this Hedgewars Lua Script, let's call it as [i]"test.lua".[/i]
Which I designed to work this way: Every vgtHealthTag and vgtSmallDamageTag visual gear will be deleted upon creation so there's no message created when a hedgehog is damaged/etc BUT ONLY IF they're not 'approved' [local = GApprovedVG]. Then I try to make one 'approved' vgtHealthTag visual gear at onNewTurn() event. I expect this last created vgtHealthTag showed up, because I mark it as 'approved' by inserting a value into GApprovedVG[vgUid] = 100.
A better look at the code should help you wrap what I'm trying/how I try to do the things.
Please take look at the code below:
[code]
local GApprovedVG = {}
function onVisualGearAdd(vg)
if GetVisualGearType(vg) == vgtHealthTag or GetVisualGearType(vg) == vgtSmallDamageTag then
if vg and GApprovedVG[vg] == nil then
DeleteVisualGear(vg)
end
end
end
function onNewTurn()
local x,y = GetGearPosition(CurrentHedgehog)
local vg = AddVisualGear(x, y, vgtHealthTag, 100, true)
SetVisualGearValues(vg, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xffffffff)
GApprovedVG[vg] = 100
end
[/code]
And as you can see; I expect that vg created at onNewTurn() should be NOT deleted because the expression "vg and GApprovedVG[vg] == nil" clearly supposed to be false, thus there should be no deletion for any 'approved' vg. But yet, when I debug the expression boolean value, it returned true, but why? Well, I think the question why can be answered by my little hypothesis: "The vgUid reference value over a gear/visual gear isn't consistent through Hedgewars Lua system, or at least there's a problem with the vgUid referencing system itself". But well, that's doesn't make sense, right? Why would the vgUid reference system inconsistent? Or because there's something messed up inside? A problem, OR ISN'T IT? Well, tbh idk for sure, and that's why I bring this personal-little-trivial-issue here, to make sure my thought and to get the right answer...
Code Note: If you remove 'DeleteVisualGear(vg)' from the code above, you will find that the vgtHealthTag created at onNewTurn() showed up perfectly.
But for now, as my best guess and bet; I just simply messed things up myself here, thus rendering the said test.lua work improperly like it should be. I just wanted to know what's my mistake here, so yeah, don't hesitate to tell my mistake (if I had any) okay =) ?
I hope you could understand the issue of me in this post, especially I hope a dev could lend me a little hand on this trivial question, hehe.
Thanks ^^
PS: To gain the best clarity, please to consider testing on your own machine by copying the provided code above then run it in Hedgewars.
[i][b][Licensed as: CC-O][/b][/i]
[center][color=#FFFFFF]╟───NW──────┼──────N╢[/color][/center]
[float=left][color=#FFFFFF]╓──────────────────╖[/color][/float][float=right] [color=#FFFFFF]╓──────────────────╖[/color][/float]
[float=left][color=#FFFF00]⠀HP:[/color] [color=#FF0000]██████████[/color] [color=#00FF00]1E9/1E9[/color][/float][float=right][color=#00FF00]1E9/1E9[/color] [color=#0000FF]██████████[/color] [color=#00FFFF]:MP [/color][/float]
[float=left][color=#FFFFFF]╙──────────────────╜[/color][/float][float=right] [color=#FFFFFF]╙──────────────────╜[/color][/float]