|
| 08 Aug 2011 02:09 PM |
I have a table where there are some values that do stuff:
{["sit"]=true,["stand"]=true,["jump"]=false}
It is basically, if set to true, that thing will happen. If false, that thing won't happen.
However, I have it so that when someone talks and says one of the keys, it will happen. But I want it so that both "stand" and "unsit" will do the same thing, but then you would have to change both. I tried this:
t = {["stand" and "unsit"]=true}
unsit worked but not stand. Then I did:
t = {["stand" or "unsit"]=true}
And the opposite happened: stand worked but not unsit. Is there a way to make it so they both work? |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 08 Aug 2011 02:41 PM |
Try not inserting new table values, just add another condition for your chatted event. I.E
if msg == "stand" or msg == "unsit" then |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2011 03:08 PM |
| I wanted it so that people who use the script can easily turn off the commands if they want to, but only one switch can be flipped for commands that do the same thing. |
|
|
| Report Abuse |
|
|
ThePHPguy
|
  |
| Joined: 05 Aug 2011 |
| Total Posts: 35 |
|
|
| 08 Aug 2011 03:34 PM |
Hi Bunny,
the reason this happened is because lua uses and and or as conditional operators. So basically when you're saying
"stand" and "unsit"
it's like saying
if "stand" then "unsit"
so of course, when checking if something is there with conditionals, anything that isn't nil or false will return true. However when you say
"stand" or "unsit"
it will return the first one that it finds to be true. If you want to try to do something like this, try using this function.
function manipulate(tab,boolean,...) local args={...} for _,v in pairs(args) do if tab[v] then tab[v]=boolean end end end
this way you could just do
manipulate(t,true,"stand","unsit")
|
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 08 Aug 2011 03:49 PM |
| ["stand"] = true, ["unsit"] = true |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2011 03:52 PM |
| @Nexun: I said I wanted them together because they do the same thing, so that if someone wants to turn them off, they only have to change one false into true. |
|
|
| Report Abuse |
|
|