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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Table handling issue

Table handling issue

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


Pages: 1  2 

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Reply #15 on Fri 08 Feb 2013 02:11 AM (UTC)
Message
There is one last issue I didn't address. You have several options. The problem is that any missing key will evaluate to nil, not false. nil == false evaluates to false. Several options include...

1) Set taraaffliction to contain every affliction, set to false. Set them to true as you afflict, false as you know they're cured.

2) use NOT. NOT changes true to false and false to true. it also changes 'nil' to true. You would do that like so:

if tarafflictions[v] == false then

changed to:

if not tarafflictions[v] then

Either option works!
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Reply #16 on Fri 08 Feb 2013 02:17 AM (UTC)

Amended on Fri 08 Feb 2013 02:23 AM (UTC) by Fadedparadox

Message
This is just one possible result:

venom_priority = {
  "slickness",
  "asthma",
  "deaf_strip",
  "sensitivity",
  "powersap",
  "blindness",
  "relapsing",
  "clumsiness",
  }

tarafflictions = {}

tarafflictions.slickness = true



function doattack()

  for k, v in ipairs(venom_priority) do
    if not tarafflictions[v] then
      Note ( "Venom: " .. v )
      break
    end -- if
  end -- for

end -- func


Another possbility!


venom_priority = {
  "slickness",
  "asthma",
  "deaf_strip",
  "sensitivity",
  "powersap",
  "blindness",
  "relapsing",
  "clumsiness",
  }

tarafflictions = {}

for k, v in pairs(venom_priority) do
  tarafflictions[v] = false
end -- for


tarafflictions.slickness = true



function doattack()

  for k, v in ipairs(venom_priority) do
    if tarafflictions[v] == false then
      Note ( "Venom: " .. v )
      break
    end -- if
  end -- for

end -- func


In fact, you can put

for k, v in pairs(venom_priority) do
  tarafflictions[v] = false
end -- for

In a function to reset the table.

For the first example, you can reset it by simply doing:


tarafflictions = {}
[Go to top] top

Posted by Dyron   (17 posts)  [Biography] bio
Date Reply #17 on Fri 08 Feb 2013 03:20 AM (UTC)
Message
Thank you so much for the examples Fadedparadox. I at least understand more of what you are saying, As for your examples, I've tried them.. without the:

doattack(...)

It refuses to call the tarafflictions variable. How do I make it call that variable that's called globally?
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Reply #18 on Sun 10 Feb 2013 02:51 AM (UTC)
Message
Dyron said:

Thank you so much for the examples Fadedparadox. I at least understand more of what you are saying, As for your examples, I've tried them.. without the:

doattack(...)

It refuses to call the tarafflictions variable. How do I make it call that variable that's called globally?


I'm not certain what you mean. tarafflictions is, in the example, global so can be called from within another function/etc, or globally.

Can you give an example of what will not work?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #19 on Sun 10 Feb 2013 08:37 PM (UTC)
Message
Dyron said:

It refuses to call the tarafflictions variable. How do I make it call that variable that's called globally?


Your use of language is confusing me. You don't "call" variables. Are you saying the variable has a different value to what you expect?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dyron   (17 posts)  [Biography] bio
Date Reply #20 on Mon 11 Feb 2013 04:10 PM (UTC)
Message
I got it figured out, thanks guys. Now on to the next problem of not being able to process gmcp.
[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.


48,381 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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]