function doattack()
local venom = {}
local tarafflictions = { "slickness" }
local i = 1
local venom_priority = {
"slickness",
"asthma",
"deaf_strip",
"sensitivity",
"powersap",
"blindness",
"relapsing",
"clumsiness",
}
for k, v in ipairs(venom_priority) do
if not tarafflictions[v] and i <= 1 then
Note ( "Venom 1: " .. v )
i = i + 1
elseif not tarafflictions[v] and i >= 2 then
Note ( "Venom 2: " .. v )
i = i + 1
break
end
end
end
Could anyone tell me how to make it so that when slickness
is present it avoids it and goes to the next venom in venom priority? I've got no clue why it keeps picking the slickness.
tarafflictions will be a constantly changing array. I set slickess in for testing but it can have up to 10-15 things in it at one time. At that rate, I don't see how to make that part work. Also, how can I move tarafflictions out of that function and make the function load it in for processing?
It's the same function, I was just doing a shortcut version of it. If the tarafflictions is local in the function it works fine.. if I move it out.. All of a sudden it doesn't work.
tarafflictions = { "slickness" }
venoms_priority = {
"slickness",
"asthma",
"deaf_strip",
"sensitivity",
"powersap",
"blindness",
"relapsing",
"clumsiness",
}
function doattack(...) -- When I do this I can now see the tarafflictions global variable.
for k, v in ipairs(venoms_priority) do
if tarafflictions[v] == false then
Note( "Venom 1: " .. v )
end
end
end
Was curious, is there anyway to do something like this? Basically, a simple check against the tarafflictions variable. If slickness is part of that variable I want to make a note saying Venom 1 is asthma.
tarafflictions = { "slickness" }
venoms_priority = {
"slickness",
"asthma",
"deaf_strip",
"sensitivity",
"powersap",
"blindness",
"relapsing",
"clumsiness",
}
function doattack(...) -- When I do this I can now see the tarafflictions global variable.
for k, v in ipairs(venoms_priority) do
if tarafflictions[v] == false then
Note( "Venom 1: " .. v )
end
end
end
That is the whole function. Not sure what else you are wanting.
function doattack(...) will now let it see a global variable.
function doattack() will not.
As for the tables help guide. I don't see where the heck it says a simple way to do it without having a ton of code. In CMUD all I've got to do is the following:
According to LUA helps I've been reading table.contain should do the same.
for k, v in ipairs(venom_priority) do
Note ( "Checking if " .. v .. " is in the table." )
if not table.contains(tarafflictions, v) then
Note ( "Venom would be: " .. v )
end
end
What I have copied/pasted is the WHOLE script file. It's just trying to make this one item.
tarafflictions - Is a variable storing all my targets afflictions. This variable will change at will by their curing.
venom_priority - Holds the order in which I want to be hitting with venoms.
The ONE(1) function doattack is trying to find the affliction I want to hit with. It's checking tarafflictions to see if the affliction is there. If it is not there, it will pick the first available affliction in venom_priority. If it is there, it will go to the next in the list.
tarafflictions needs to be a global variable due to many triggers will affect it in the future. If somebody cures slickness, I will then want to update tarafflictions to delete it from that list.
for k, v in ipairs(venoms_priority) do
if tarafflictions[v] == false then
Note( "Venom 1: " .. v )
end
end
The v in tarafflictions should be looping through the venoms_priority variables, as far as I understand. So thus should be doing key by affliction..
Should first be tarafflictions[slickness] then tarafflictions[asthma] then tarafflictions[deaf_strip].. etc.. Am I understanding this wrong?
which, since all we have is tarafflictions[1], will return nil.
nil is not false. so what Nick is saying, is that you will ALWAYS get a false return. what he also said, 'tarafflictions = { slickness = true }' will cause this.
for k, v in ipairs(venoms_priority) do
if tarafflictions[v] == false then
Note( "Venom 1: " .. v )
end
end
The v in tarafflictions should be looping through the venoms_priority variables, as far as I understand. So thus should be doing key by affliction..
Should first be tarafflictions[slickness] then tarafflictions[asthma] then tarafflictions[deaf_strip].. etc.. Am I understanding this wrong?
Not quite.
the V in 'venoms_priority' is used. when you use tarafflictions[v] in your if statement, you are looking for a KEY in tarafflictions with the same name as the VALUE in venoms_priority. The key you made is 1. The value is "slickness". What you need to do is change the tarafflictions table, as per Nick and my post above. It needs to have KEYs of the venom name, and VALUES of true.
There is one last issue I didn't address. You have several options. The problem is that any missing key will evaluate to nil, not false. nil == false evaluates to false. Several options include...
1) Set taraaffliction to contain every affliction, set to false. Set them to true as you afflict, false as you know they're cured.
2) use NOT. NOT changes true to false and false to true. it also changes 'nil' to true. You would do that like so:
venom_priority = {
"slickness",
"asthma",
"deaf_strip",
"sensitivity",
"powersap",
"blindness",
"relapsing",
"clumsiness",
}
tarafflictions = {}
tarafflictions.slickness = true
function doattack()
for k, v in ipairs(venom_priority) do
if not tarafflictions[v] then
Note ( "Venom: " .. v )
break
end -- if
end -- for
end -- func
Another possbility!
venom_priority = {
"slickness",
"asthma",
"deaf_strip",
"sensitivity",
"powersap",
"blindness",
"relapsing",
"clumsiness",
}
tarafflictions = {}
for k, v in pairs(venom_priority) do
tarafflictions[v] = false
end -- for
tarafflictions.slickness = true
function doattack()
for k, v in ipairs(venom_priority) do
if tarafflictions[v] == false then
Note ( "Venom: " .. v )
break
end -- if
end -- for
end -- func
In fact, you can put
for k, v in pairs(venom_priority) do
tarafflictions[v] = false
end -- for
In a function to reset the table.
For the first example, you can reset it by simply doing:
Thank you so much for the examples Fadedparadox. I at least understand more of what you are saying, As for your examples, I've tried them.. without the:
doattack(...)
It refuses to call the tarafflictions variable. How do I make it call that variable that's called globally?
Thank you so much for the examples Fadedparadox. I at least understand more of what you are saying, As for your examples, I've tried them.. without the:
doattack(...)
It refuses to call the tarafflictions variable. How do I make it call that variable that's called globally?
I'm not certain what you mean. tarafflictions is, in the example, global so can be called from within another function/etc, or globally.