[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Posting to variables with different names

Posting to variables with different names

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Wed 17 Mar 2010 05:21 AM (UTC)

Amended on Wed 17 Mar 2010 05:22 AM (UTC) by Tiopon

Message
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.
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #1 on Wed 17 Mar 2010 01:28 PM (UTC)
Message
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
[Go to top] top

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #2 on Wed 17 Mar 2010 01:55 PM (UTC)

Amended on Wed 17 Mar 2010 02:55 PM (UTC) by Tiopon

Message
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.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Wed 17 Mar 2010 04:16 PM (UTC)
Message
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?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #4 on Wed 17 Mar 2010 06:20 PM (UTC)
Message
Quite. I should have said that Table["Value1"]["Value2"] == Table.Value1.Value2 instead of skipping those quotations. :) It does matter... Heh.
[Go to top] 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.


14,443 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]