Newb question

Skylark
Posts: 46
Joined: Mon Feb 22, 2010 12:38 am

Re: Newb question

Post by Skylark »

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.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Newb question

Post by demonnic »

triggerID = tempTrigger(2,send("oi"))


triggerID will hold the ID for that tempTrigger. you can then


killTrigger(triggerID)

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Newb question

Post by naftali »

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.

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: Newb question

Post by ixokai »

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

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Newb question

Post by demonnic »

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?

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Newb question

Post by naftali »

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?

Skylark
Posts: 46
Joined: Mon Feb 22, 2010 12:38 am

Re: Newb question

Post by Skylark »

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.

guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: Newb question

Post by guy »

ixokai wrote:
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.
Well, it's possible with some tricks.

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
and you could turn that into a function like

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
Just remember that 'print' displays on a text console, not in Mudlet. To have stuff show up there you need to use one of the *echo() functions.

Skylark
Posts: 46
Joined: Mon Feb 22, 2010 12:38 am

Re: Newb question

Post by Skylark »

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?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Newb question

Post by Heiko »

You need to upgrade to a new version of Mudlet. Current is 1.1.1.

Post Reply