how to use matches as variable name

Post Reply
mui
Posts: 2
Joined: Sun Jul 13, 2014 7:11 pm

how to use matches as variable name

Post by mui »

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!

User avatar
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

Post by SlySven »

You should be able to achieve the same result by doing this DIRECTLY in the command line:

Code: Select all

lua xxx = yyyy
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. ;)

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: how to use matches as variable name

Post by Jor'Mox »

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])

mui
Posts: 2
Joined: Sun Jul 13, 2014 7:11 pm

Re: how to use matches as variable name

Post by mui »

Both solutions work! The commandline alias seems very useful. Thanks guys!

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: how to use matches as variable name

Post by Oneymus »

As another alternative, you can index into the _G table (Lua's global table) with a string. So, you could do something like...
Code: [show] | [select all] lua
_G[matches[2]] = matches[3]

Post Reply