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.
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.
Newb question
Re: Newb question
triggerID = tempTrigger(2,send("oi"))
triggerID will hold the ID for that tempTrigger. you can then
killTrigger(triggerID)
triggerID will hold the ID for that tempTrigger. you can then
killTrigger(triggerID)
Re: Newb question
What he said for the first part. For the second, I think it happens that way by default - perhaps not if you do
table.one = table.two
but I think if the first thing isn't a table, so
table = table.two
it should work the way you're talking about. I remember it being much more difficult for me to force it to NOT behave the way you want.
table.one = table.two
but I think if the first thing isn't a table, so
table = table.two
it should work the way you're talking about. I remember it being much more difficult for me to force it to NOT behave the way you want.
Re: Newb question
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.
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.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.
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
Re: Newb question
Yeah, what ixokai said...
But, to expound and perhaps be able to help, what is your desired end result?
We may be able to suggest a good way of accomplishing that, as opposed to a bunch of discussion on the theories behind the way lua does things. Good stuff, but not an answer for the thing you actually want to accomplish.
so.. tell me what it is you actually want to get -done- with this code?
But, to expound and perhaps be able to help, what is your desired end result?
We may be able to suggest a good way of accomplishing that, as opposed to a bunch of discussion on the theories behind the way lua does things. Good stuff, but not an answer for the thing you actually want to accomplish.
so.. tell me what it is you actually want to get -done- with this code?
Re: Newb question
Huh. Perhaps I'm confused about what we're discussing here. From what you're saying I would think that the script found at http://lua-users.org/wiki/CopyTable wouldn't be necessary. What am I confused about?
Re: Newb question
Ixokai, thank you very much, that was extremely helpful.
Don't worry about what I wanted to get done with it, my question arose several times under different circumstances, and I've since resolved the problems in an entirely satisfactory way.
Don't worry about what I wanted to get done with it, my question arose several times under different circumstances, and I've since resolved the problems in an entirely satisfactory way.
Re: Newb question
Well, it's possible with some tricks.ixokai wrote:Its not possible. Why, and the full implications of this, are actually slightly hard to explain.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.
Code: Select all
myTable = {}
fruit = {}
myTable.things = "fruit.apple"
fruit.apple = 0 -- initial setting
print(fruit.apple) -- displays 0
assert(loadstring(myTable.things .. " = " .. tostring(2)))()
print(fruit.apple) -- displays 2
Code: Select all
function funky_assign (item, value)
assert(loadstring("local param = ... " .. item .. " = param"))(value)
end
funky_assign (myTable.things, "John Sherbet")
print(fruit.apple) -- displays John Sherbet
Re: Newb question
The 'Show TimeStamps' button no longer shows its timestamps in the main window. When clicked, it changes cosmetically, but the timestamps no longer appear, and the main window does not change at all. The timestamps DO appear when scrolling back through the buffer, however.
Any ideas?
Any ideas?
Re: Newb question
You need to upgrade to a new version of Mudlet. Current is 1.1.1.