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
➜ Lua
➜ 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 page
Posted by
| Tiopon
USA (71 posts) 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 > %1) then
work_table[JobNumber].minname = %1
end
if (not work_table[JobNumber].maxname or work_table[JobNumber].maxname < %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. | Top |
|
Posted by
| Larkin
(278 posts) 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
| Top |
|
Posted by
| Tiopon
USA (71 posts) 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. | Top |
|
Posted by
| Twisol
USA (2,257 posts) 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 | Top |
|
Posted by
| Tiopon
USA (71 posts) 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. | 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.
16,398 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top