Posting to variables with different names

Posted by Tiopon on Wed 17 Mar 2010 05:21 AM — 5 posts, 21,455 views.

USA #0
I'm trying to have it posting variables based on which level the job is at. I'm wanting it to post to work_table[JobNumber].minpay[1-9] or whatever level it is. Here's the trigger I'm running... it turns itself off and disables the other job parsing trigger. That part works... the issue is that it isn't setting on the right name, it's setting as work_table[JobNumber].minname and work_table[JobNumber].maxname...

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^You earn \$([0-9]*)\.$"
   name="job_stopper"
   regexp="y"
   send_to="12"
   sequence="70"
  >
  <send>table.foreach (work_table, function (k, v)
       if (v.name == GetVariable ("Current_Job")) then JobNumber = k
       end -- if 
      end -- function
      )

EnableTrigger ("job_line", false)
EnableTrigger ("job_stopper", false)

local minname = "minpay" .. work_table[JobNumber].level
local maxname = "maxpay" .. work_table[JobNumber].level

if (not work_table[JobNumber].minname or work_table[JobNumber].minname &gt; %1) then
work_table[JobNumber].minname = %1
end

if (not work_table[JobNumber].maxname or work_table[JobNumber].maxname &lt; %1) then
work_table[JobNumber].maxname = %1
end

SetVariable ("work_table", serialize.save ('work_table'))
</send>
  </trigger>
</triggers>


The actual text is something like
Quote:
You earn $73.
Amended on Wed 17 Mar 2010 05:22 AM by Tiopon
#1
The syntax t.name is equivalent to t["name"], so to use the contents of a variable as a field/key, you need to use the square brackets (and no quotes).
work_table[JobNumber][maxname] = %1
USA #2
Beautiful, thanks. Will test that right now... Didn't see anything easily listed that said that Table[Value1][Value2] was equivalent to Table.Value1.Value2 (if I'm understanding properly).

Or are they not equivalent, meaning that the whole table needs to be converted to the new system? :) This is why coding the week of DST is a bad idea... My brain doesn't work as well as I'd like.

Edit:
Does seem to have worked. Would probably be good to list those as equivalent somewhere in the table helps, especially important when dealing with variables... though it might be there and I just failed to recognize it.
Amended on Wed 17 Mar 2010 02:55 PM by Tiopon
USA #3
Tiopon said:
Beautiful, thanks. Will test that right now... Didn't see anything easily listed that said that Table[Value1][Value2] was equivalent to Table.Value1.Value2 (if I'm understanding properly).


It's not. Table["A"] == Table.A != Table[A]. The difference is that .A is simply shorthand for ["A"]. When you use [A], though, you're actually using the value of a variable somewhere for that key. So if level = 10, table.level would get the value at the "level" key, but table[level] would get the value at the 10 key. Does that make sense?
USA #4
Quite. I should have said that Table["Value1"]["Value2"] == Table.Value1.Value2 instead of skipping those quotations. :) It does matter... Heh.