Hi I am new to mudlet and am trying to make an alias setvariable xxx yyy where xxx is the name of an existing variable and yyy is the new value I wish to assign it.
I have tried
matches[2] = matches[3] , which doesn't work
as well as,
{matches[2]) = matches[3] , which gives me syntax error.
Hope to get some help here. Thanks!
how to use matches as variable name
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: how to use matches as variable name
You should be able to achieve the same result by doing this DIRECTLY in the command line:
F.Y.I. This uses the "run lua code" alias defined in the "run-lua-code-v4" that is one of the default items that gets inserted into a new connection profile! Perhaps, when we both understand how that works one of us might be better able to answer the question.
Code: Select all
lua xxx = yyyy
Re: how to use matches as variable name
The problem is that your matches are strings, and variable names are... something else. So you need to use the loadstring function, like this: loadstring(matches[2] .. " = " .. matches[3])
Re: how to use matches as variable name
Both solutions work! The commandline alias seems very useful. Thanks guys!
Re: how to use matches as variable name
As another alternative, you can index into the _G table (Lua's global table) with a string. So, you could do something like...