
Originally Posted by
Sechs
Mote I implemented all of your suggestions, thanks once more!
A couple of questions so I can understand better the code though, especially within the function handle_siphoning() (which is awesome btw)
- What's happening in line 579 of your SMN lua? "local intense = get_weather_intensity()" In the same line you are defining a local variable AND you are assigning a value to that variable using the result of the function you're calling? Did I interpret this right?
- Embarassing to ask but what's going on "return (world.weather_id % 2) + 1"? It's a line of your custom "get weather intensity" function. I don't understand what's happening inside the brackets. (altough I get the result of brackets should be either 0 or 1, to be summed with the +1 outside?)
- Gave a look at Elemental Gear Utility but need more help. I spotted gear.ElementalGorget.name = get_elemental_item_name("gorget", weaponskill_elements) or gear.default.weaponskill_neck or "". With such a variable then inside my sets I could do something like setname = {head="", neck=gear.ElementalGorget.name, ear1="", ...}. Did I get it right?
But I still don't understand. Let's say I define Gorgetname = "item1" or "item2" or "item3" and then in my set I go Setname = {neck=Gorgetname}. In which order do the items get processed? Left to right? Right to left? Which gets priority? Let's say for instance I have all Item1, Item2 and Item3 in inventory, so all 3 possibilities are true. Which one would Gearswap prefer for my set in such a circumstance? - For send_command lines, what's the different between ('input ...) and ('@input ...)?
1. You are correct in your interpretation. setting a variable with the local attribute is just a way to limit the memory used on your program. It tells the lua that when the function is done processing, it doesn't need to keep the memory allocated for that variable.
2. without looking as the weather.lua file in libs, what that function seems to do is take the property from that file single weather would be an even number and double weather would be an odd number. The % 2 is a modular calculation, that divides the number by 2 and gives you the remainder. So if you say had single sand storm weather up. If its id was 4 then that calculation would be 4 % 2 = 0, then add 1 and you get 1 for the intensity.
3. Using the or in this case will give you the farthest left non nil value, so Gorgetname = nil or "item2" or "item3" would make Gorgetname = "item2". This allows you to eliminate some if statements in your file. Here is how I commonly use this with magic.
local equipset = set_combine(sets[spell.skill], sets[spell.skill][spell.english] or sets[spell.skill][spell_group] or {}).
What this does is creates a set with baseset sets[spell.skill] which I always have assigned. It then adds to the set sets[spell.skill][spell.english] if that is not nil. If it is nil then it adds sets[spell.skill][spell_group] if it isn't nil. If both are nil then it just adds an empty table.
Essentially:
Code:
local equipset = set_combine(sets[spell.skill], sets[spell.skill][spell.english] or sets[spell.skill][spell_group] or {})
Is the same as:
Code:
local equipset = sets[spell.skill]
if sets[spell.skill][spell.english] ~= nil then
equipset = set_combine(equipset, sets[spell.skill][spell.english])
elseif sets[spell.skill][spell_group] ~= nil then
equipset = set_combine(equipset, sets[spell.skill][spell_group])
end
4. I don't know that one.