Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Need assistance with ordered if checks
Need assistance with ordered if checks
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Hoplo
(16 posts) Bio
|
Date
| Tue 07 Aug 2012 06:27 AM (UTC) Amended on Tue 07 Aug 2012 08:11 AM (UTC) by Hoplo
|
Message
| Hello. I am trying to make a function that checks a table with "group" information and tries to cast "heal" when certain conditions are met.
This is what I have so far.
function dohealcheck(name, line, wildcards)
maintank = GetVariable("maintank")
charname = GetVariable("chname")
ishealing = GetVariable("ishealing")
mhealer = GetVariable("mainhealer")
htarget = ""
Note ("Is Healing? "..ishealing)
if ishealing == "false" then
if mhealer = "true" then
for n,g in pairs(groupArr) do
if n == maintank then
if g.here == "Y" and g.hits == "bad" or
g.here == "Y" and g.hits == "v.bad" or
g.here == "Y" and g.hits == "awful" or
g.here == "Y" and g.hits == "dying" then
Note ("Heal Target Found : Main " ..n)
doheal(n)
return ishealing
end -- if
end -- if
end -- for
end -- if
-- Check Dying
for n,g in pairs(groupArr) do
if g.here == "Y" and g.hits == "dying" or
g.here == "Y" and g.hits == "awful" then
Note ("Heal Target Found : Dying " ..n)
doheal(n)
return ishealing
end
end
-- Check Self
if n == charname then
for n,g in pairs(groupArr) do
if g.here == "Y" and g.hits == "bad" or
g.here == "Y" and g.hits == "v.bad" then
Note ("Heal Target Found : Self " ..n)
doheal(n)
return ishealing
end
end
end
-- Check Everyone Else
for n,g in pairs(groupArr) do
if g.here == "Y" and g.hits == "v.bad" or
g.here == "Y" and g.hits == "bad" then
Note ("Heal Target Found : Group " ..n)
doheal(n)
return ishealing
end
end
end
end -- function
The problem is that despite my best efforts to check for priorities (tank first, then other dying people, then self, etc) the function will run through the entire series of checks on the first person in the group table and then the second and so on.
This is a result of what happens.
Member Hits Here
----------------------------
Yasmin awful Y
Is Healing? false
Heal Target Found : Dying Yasmin
Vitor v.bad Y
Is Healing? true
This is as intended, healing the awful first. However, when the members are switched in order the problem is revealed.
Member Hits Here
---------------------------
Vitor v.bad Y
Is Healing? false
Heal Target Found : Group Vitor
Yasmin awful Y
Is Healing? true
I am sure there is something simple I am missing. Any assistance would be very appreciated. | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #1 on Wed 08 Aug 2012 07:50 PM (UTC) Amended on Wed 08 Aug 2012 07:51 PM (UTC) by Fiendish
|
Message
| is an obvious error. That should be ==. Also please put parentheses around all those conditional groups. You have no idea what those are supposed to do. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Hoplo
(16 posts) Bio
|
Date
| Reply #2 on Mon 13 Aug 2012 08:02 AM (UTC) Amended on Mon 13 Aug 2012 08:03 AM (UTC) by Hoplo
|
Message
| Thanks Fiendish. Forgot to put all the checks in ().
What I am trying to do is set up a priority system where a function goes through the entire groupArr table and then will cast a spell on the character with the lowest health.
example: group
--------------------------------------------------
Bul bad rested standing
Rabi v.bad rested standing
Rev bad rested standing
Tina awful rested standing
and what the groupArr table looks like
groupArr {} that looks like this after tprint (groupArr)
"Bul":
"pos"="standing"
"mv"="rested"
"hits"="bad"
"Rabi":
"pos"="standing"
"mv"="rested"
"hits"="v.bad"
"Rev":
"pos"="standing"
"mv"="rested"
"hits"="bad"
"Tina":
"pos"="standing"
"mv"="rested"
"hits"="awful"
The problem is that no mater what I seem to think of all of the checks run through the first name in the table. So "Bul" will be checked through all the health checks and if it matches ANY of them it gets healed; instead of running through the entire group table and healing the lowest.
I have spent almost a week trying various orders of if checks to no avail. I am sure there is a simple solution I just can not seem to figure it out. | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #3 on Mon 13 Aug 2012 07:59 PM (UTC) |
Message
| Uhm.. You first test will always hit on the first person. What you need to be doing is more complex, like:
temp = -1
tstat = ""
if ishealing == "false" then
if mhealer = "true" then
for n,g in pairs(groupArr) do
if n == maintank then
if g.here == "Y" then
if g.hits = "bad" and tstat <> "v.bad" and tstat <> "awful" and tstat <> "dying" then
temp = n
tstat = g.hits
else
if g.hits = "v.bad" and tstat <> "awful" and tstat <> "dying" then
temp = n
tstat = g.hits
else
if g.hits = "awful" and tstats <> "dying" then
temp = n
tstat = g.hits
else
if ghits = "dying" then
temp = n
tstat = g.hits
end -- if
end -- if
end -- if
end -- if
end -- if
end -- if
end -- for
if tstat <> "" then
Note ("Healing Target Found : Main " ..temp)
doheal(temp)
return ishealing
end -- if
end -- if
No idea if that code is right, BTW, but, basically. And, there is probably some way to simplify it a bit, maybe.. Instead of using strings, if it was using values, like 0, 1, 2, 3, etc. to track the condition, for example, the above could have been solved with (and is a lot less messy):
-- Some earlier point, to cast the results into easily
-- compared integers.
if hit = "bad" then
g.hits = 1
end
if hit = "v.bad" then
-- etc.
...
temp = -1
tstat = ""
...
for n,g in pairs(groupArr) do
if n == maintank then
if g.here == "Y" then
if g.hits > tstat then
temp = n
tstat = g.hits
end if
end if
...
You could still do it, with some strange Boolean math, assuming the language allowed it. And some languages let you, I think, created ordered sets, so you create a set, and then when comparing your new value against the set, it automatically knows that 'dying' is higher than 'bad', in that set, but its just easier (if you can't create such sets) to, at some earlier point, like where you receive the conditions from the mud in the first place, to convert them into integer, and work with numbers. ;)
You needed to not just testing against what ever condition there is in each pair, but also have to compare each pair. All your code was doing is looking for the first pair it could find that matched *any* criteria. | Top |
|
Posted by
| Hoplo
(16 posts) Bio
|
Date
| Reply #4 on Mon 13 Aug 2012 11:14 PM (UTC) |
Message
| Gives me something to work with for time being, thanks :)
And ya i can change the health to a numerical system, either at check or within the actual healing code. Thanks | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
18,829 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top