Skylark wrote:I have my own newb question. Two, actually.
Say I make a temporary trigger;
tempTrigger(2, send("oi"))
How exactly would I go about disabling this with killTrigger()? I don't know how to get the ID of a temporary trigger so I can turn it off before it fires.
As others have said, store the result of calling tempTrigger, and pass that to killTrigger.
Skylark wrote:Also, is it possible to expand the contents of a variable or table value and set the content equal to something? For example, say I want to set fruit.apple equal to 1. I want to do something like the following;
table.things="fruit.apple"
table.things=1
except that instead of having table.things be 1, I want fruit.apple to be set to 1.
Thanks.
Its not possible. Why, and the full implications of this, are actually slightly hard to explain. Basically, you should abandon the entire concept of "variable" from your mental frame of reference. "Variable" implies a situation with boxes, where you put values in, and maybe even situations where you can share a box in more then one place. That doesn't exist here.
Lua really only has two types of variables: simple, immutable scalars (strings, numbers, true/false), and a hash / associative array.
There are no "variables"; when you do:
x = 5
You're really doing:
_G["x"] = 5
As you go around doing loops, new tables are constructed behind the scenes to be the local namespace, and so on. Now, if you think of things in those terms, you may start to see why your question isn't possible. Everything you do is actually in a very simple system: basic values, or simple key->value pairs.... then it just builds from this -very- basic framework, letting values be other key->value pairs, which might have more key->value pairs.
Basic values are immutable, unchangeable.
x = 1
x = 2
Here, you are not creating a variable "x", and assigning a value 1 to it, then changing that value to 2.
You're adding a key to the current namespace table, and assigning an object "1" to it. Later, you are -discarding- that object "1" and -replacing- it with an entirely new object, "2".
There's no actual connection between the previous object and the new one; that they share the same type, and that it is an increment of the original, is pure chance. Or, rather, your application code. It could be something else entirely, say, a string.
The key here is that the *name* is just... some string in some table, and the *object* can be anything. The reason you can't "expand" one variable into another is that there is no way to actually represent any kind of -relationship- between one object and another, except through the keys of various tables.
Let's say you have:
fruit.apple = 1
And over here:
tbl.thing = fruit.apple
The first statement has a key->value pair, "fruit", and its setting the object "1" to be the value of the key "apple".
THe second statement is another key->value pair, and its looking in "fruit" and getting its "apple" key, and assigning the value object to its "thing" key. Now, you have the same object -- a "1" -- in two different key->value pairs. But there's no -relationship- between those two key->value pairs. If one decides to throw away its reference to "1", the other can't possibly know. There's no interaction. Its all just a series of simple tables.
HTH