Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Prioritization code

CaelanCaelan Member Posts: 381 ✭✭✭ - Distinguished
So, I'm writing my own curing. I think most people know this.  

What I'm having trouble with, is I have a table of plant-based affs (or, ones that can be cured with plants)
Then I have another for the order I want it cured in.

But it doesn't seem to work.  As in, there's times it will still cure randomly (or at least seems to)

My herb list goes like this:                                               and my priorities go :

herbcures = {                                                                  herbprios = {

<affliction> = "<cure>",....                                            [1] = "<aff name>",


[code]

if I can cure with plants then

  for i = 1, #herbprios do

     for aff, cure in pairs(herbcures) do

       if table.contains(afflicted_by, aff) then

         if cure ~= "" then -- some afflictions might not have cures

            curing stuff, timers, echoes

             return

          end

     end

  end

end

end[/code]


Anyone know of a better way to make sure it constantly is checking the proper order? Or is the prio table set up wrong?
Just, don't be the 3000th person to say "lol get SVOF".  I don't want SVOF

Comments

  • AntoniusAntonius Member Posts: 3,842 @@ - Legendary Achaean
    If you don't want svof, don't get it. I don't personally see the point in implementing curing logic with server side curing existing though.

    That said, pairs doesn't guarantee an order, and judging by your post you've got a dictionary that you almost want to treat as an ordered list. Your structure is almost certainly wrong.
  • CaelanCaelan Member Posts: 381 ✭✭✭ - Distinguished
    So then how would I go about making an ordered list?  

  • AntoniusAntonius Member Posts: 3,842 @@ - Legendary Achaean
    On my phone, so hard to go into super detail, but an ordered list is basically:

    variable = {"paralysis", "asthma", "clumsiness", etc}

    Then you use ipairs to iterate over that. The moment you do variable["key"] = value you have a dictionary, and I'm not sure what would happen when trying to iterate over it.
  • CaelanCaelan Member Posts: 381 ✭✭✭ - Distinguished
    edited January 29
    Ok. Thanks  (and writing my own because my ping is faster than SS)

  • SeverinaSeverina Member Posts: 86 ✭✭✭ - Distinguished
    Caelan said:
    So, I'm writing my own curing. I think most people know this.  

    What I'm having trouble with, is I have a table of plant-based affs (or, ones that can be cured with plants)
    Then I have another for the order I want it cured in.

    But it doesn't seem to work.  As in, there's times it will still cure randomly (or at least seems to)

    My herb list goes like this:                                               and my priorities go :

    herbcures = {                                                                  herbprios = {

    <affliction> = "<cure>",....                                            [1] = "<aff name>",


    [code]

    if I can cure with plants then

      for i = 1, #herbprios do

         for aff, cure in pairs(herbcures) do

           if table.contains(afflicted_by, aff) then

             if cure ~= "" then -- some afflictions might not have cures

                curing stuff, timers, echoes

                 return

              end

         end

      end

    end

    end[/code]


    Anyone know of a better way to make sure it constantly is checking the proper order? Or is the prio table set up wrong?
    Just, don't be the 3000th person to say "lol get SVOF".  I don't want SVOF
    My first observation here is that you aren't iterating over your herbprios table at all. You're iterating through herbcures #herbprios (the 'length' of, or how many key-value pairs exist in the herbprios table, for those unfamiliar with the syntax) times and otherwise ignoring the herbprios table. I would fix that first.

    for k,aff in ipairs(herbprios) do
       if table.contains(afflicted_by,aff)
          if herbcures[aff] then cure = herbcures[aff] end
          if cure ~= "" then -- some afflictions might not have herb cures
             -- curing stuff, timers, echoes
             return
          end
       end
    end


    As mentioned above, you do want to be meticulous with how you structure your tables - either as unordered tables or ordered arrays, and use pairs() and ipairs() respectively for iteration, but at first glance the tables look fine.

Sign In to Comment.