variables with a space in them

95 views
Skip to first unread message

Ernestyna

unread,
Jul 13, 2026, 6:15:08 AM (12 days ago) Jul 13
to lu...@googlegroups.com
hello!

at first, i'd like to say i have no experience with lua coding nor know how it works. i am an admin on a fandom wiki so i guess my coding skills only come to some limited html expressions. so sorry if i use some incorrect wording!

yesterday i decided to implement a new module to our wiki called Line distributions. basically, it just shows a ranking of the group's members based on how much they sang in a song. it uses local groups with members to work properly where some of the members have a space in their name, e.g. "Kim Lip", "Go Won", or "Olivia Hye". it also uses another module, called Index to attribute each members their respective color. this is where my problem arises. i cannot enter a variable with a space in it, otherwise the whole code would break. temporarily, i have conjoined the two-worded names of members as this feature is still in a testing phase so it wouldn't make much of a difference for the admins anyway. so my question is—is it possible to make a variable with a space in it? i have tried adding an underscore or a plus symbol, even an invisible special symbol, however none of these seem to work like i'd like to.

i'm looking forward to your response. if you wish to see how the module works, you can see it in my sandbox page. feel free to edit anything too, lol. there are some other few issues but i'll come back to these later. thank you so much!!!

Spar

unread,
Jul 13, 2026, 6:57:27 AM (11 days ago) Jul 13
to lu...@googlegroups.com
You can't. But you can either:
  1. transform input to snake_case before making a variable (applicable only if generate Lua script by some other script)
  2. Store them as string keys in the table. {["Key with spaces"] = "some value"}
 
Probably you don't even need to name them as variable names. Table will be fine.
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CA%2Bgg%2B6Y061y-fWiS4-cOeDKa3NnE6tBPmm%2BsDpgJ9qyK_3wqag%40mail.gmail.com.

Pierpaolo BERNARDI

unread,
Jul 13, 2026, 7:13:15 AM (11 days ago) Jul 13
to lu...@googlegroups.com
On Mon, Jul 13, 2026 at 12:15 PM Ernestyna <ernest...@gmail.com> wrote:

> yesterday i decided to implement a new module to our wiki called Line distributions. basically, it just shows a ranking of the group's members based on how much they sang in a song. it uses local groups with members to work properly where some of the members have a space in their name, e.g. "Kim Lip", "Go Won", or "Olivia Hye". it also uses another module,

I think that this is a terrible design. Members should not be modeled
by variables.

The names should be keys to tables, and must be kept as strings

Perhaps if you tell us more details about the task, we can give more
specific help!

Frank Kastenholz

unread,
Jul 13, 2026, 8:43:46 AM (11 days ago) Jul 13
to lu...@googlegroups.com
You can not do something like
    Kim Lip = 123
However, you could say
  Some_datatable[“Kim Lip”] = 123

However, using a person’s name as a key may bit be the wisest choice. What happens if there are two people named “Kim Lip”?  

Martin Eden

unread,
Jul 13, 2026, 9:11:54 AM (11 days ago) Jul 13
to lu...@googlegroups.com
On 2026-07-13 13:12, Pierpaolo BERNARDI wrote:
> On Mon, Jul 13, 2026 at 12:15 PM Ernestyna<ernest...@gmail.com> wrote:
>
>> yesterday i decided to implement a new module to our wiki called Line distributions. basically, it just shows a ranking of the group's members based on how much they sang in a song. it uses local groups with members to work properly where some of the members have a space in their name, e.g. "Kim Lip", "Go Won", or "Olivia Hye". it also uses another module,
> I think that this is a terrible design. Members should not be modeled
> by variables.
Second that. Code should have minimal dependency of data.
> Perhaps if you tell us more details about the task, we can give more
> specific help!
Actually OP provided link to code:

    https://loonatheworld.fandom.com/wiki/Module:LD

I'll refrain from advice here. ( I started my Lua journey
from World of Warcraft. There it seemed that doing
the job is more important than how it's done. )

-- Martin

Ernestyna

unread,
Jul 13, 2026, 9:14:24 AM (11 days ago) Jul 13
to lua-l
i'm grateful for everyone's answers! i'll try to explain the concept more so you can all understand better.

the Line distribution module acts as a way to rank the members of a group based on how many lines they sang (or rapped/talked) in a song. the amount of seconds and percentage is taken from an external video and entered into arguments when the module is invoked on a page.

Zrzut ekranu 2026-07-13 145656.png

for reference:
singer is based on local groups
image uses files from the wiki
— all non-standard names such as HeeJin or Olivia Hye are "members" [variables?] of the local groups, e.g. LOONA

Zrzut ekranu 2026-07-13 150219.png

i know the code is not pleasant to look at, and there are definitely better ways to write some parts...

Zrzut ekranu 2026-07-13 150545.png

continuing on! the module also uses another module called Index which acts as a color scheme(?) for the members

Zrzut ekranu 2026-07-13 150829.png

so when the ranking is shown, each member has their respective color attributed to them if the variable entered when invoking the Line distribution module is the same as in the Index module. and that is a problem because i cannot enter "Kim Lip" in the Index module, only "KimLip" or "Kim_Lip".
i think the best option would be to name the local groups' + Index's variables something different BUT make the output as original.

EXAMPLE:

Line distribution
local groups = {
     LOONA = { "HJ", "HN", "HS", "YJ", "VV", "KL", "JS", "CR", "YV", "CU", "GW," "OH" }
}

Index
return {
     HJ = { color = "blahblah", border = "blahblah" },
}

Zrzut ekranu 2026-07-13 151345.png

okay i'll stop writing for now so i can see what you guys think LOL

also, one quick question—what is a table?

Ernestyna

unread,
Jul 13, 2026, 9:19:26 AM (11 days ago) Jul 13
to lua-l
On Monday, July 13, 2026 at 2:43:46 PM UTC+2 Frank Kastenholz wrote:
What happens if there are two people named “Kim Lip”?  

i guess nothing! whenever there is a duplicate argument call in a template fandom ignores it and attributes a category to the page: Pages using duplicate arguments in template calls

Zrzut ekranu 2026-07-13 151823.png

Pierpaolo BERNARDI

unread,
Jul 13, 2026, 9:49:11 AM (11 days ago) Jul 13
to lu...@googlegroups.com
OK. The misunderstandings are caused by your use of the word "variable".  What you call variable, actually is a string :)

For the original question: when you need to refer to Kim Lip, use "Kim Lip".

Try perusing this book: https://www.lua.org/pil/2.5.html



Jure Bagić

unread,
Jul 13, 2026, 10:11:24 AM (11 days ago) Jul 13
to lu...@googlegroups.com
> also, one quick question—what is a table?

It is a Lua value (an object) that offers key-value mapping and
associative arrays (a list, but ignore this for now).
What you call a group is actually a TABLE.
Here is a table:

> local t = { a = 5 }

Table definition begins with '{' and ends with corresponding '}',
anything inside of those braces are table elements.
The above table has a single key-value mapping (a single element),
the string "a" mapped to (or assigned) the integer VALUE 5.
This table VALUE is assigned to the (local) VARIABLE 't'.
So the following two lines:

> print(t.a)
> print(t["a"])

will print (the '> ' prefix is how I highlight code/output in email):

> 5
> 5

Now you can also do:

> local t = { "MyName" }

this is equivalent to:

> local t = { [1] = "MyName" }

where the integer VALUE 1 is mapped to the string VALUE "MyName".
(This table VALUE is once again assigned to the local VARIABLE 't'.)
So this:

> print(t[1])

will print the following string VALUE

> MyName

You will notice that you need to use index notation ('[' ']') as
opposed to dot access ('.') for non-string key values or strings
that do not form a valid name/identifier.
In other words the 't.bla' is syntax sugar for 't["bla"]'.

Finally, the 'local' keyword is put before the VARIABLE name,
it means the VARIABLE is only visible to the current
script/function/block/chunk
where this VARIABLE is declared.
If you want to access a VARIABLE (such as 't') outside of that
script/function/block/chunk (perhaps from a different script/file that
requires
or executes after that script) then you can omit 'local' from the
examples above

> t = { [1] = "MyName" }

The above is global VARIABLE named 't',
assigned the VALUE of a table that has a single
element (key-value pair). The key is the integer
VALUE 1 that is mapped to string VALUE "MyName".
Of course, the following would be equivalent to the above

> t = { "MyName" }

and

> t = { "MyName", "OtherName" }

is actually

> t = { [1] = "MyName", [2] = "OtherName" }

I don't know if you knew these things already but I just couldn't understand
your email well enough (confusing terminology).
Hopefully it helps a bit to solve your problem, check out Lua reference
manual
(do 'print(__VERSION)' to see which version of reference manual to use).

I suggest learning Lua a bit and learning to separate what is part of
core/standard
Lua and the platform (Fandom) that embeds (or uses in some way?) Lua.
(Keep in mind, the above terminology I used is not so precise, just a
few beginner
friendly lines of code/explanations.)

-- Jure

Ernestyna

unread,
Jul 13, 2026, 3:03:40 PM (11 days ago) Jul 13
to lua-l
thank you guys for all your help! i managed to make everything work by changing the code to this:

Zrzut ekranu 2026-07-13 210255.png

final result:

Zrzut ekranu 2026-07-13 210304.png

Jure Bagić

unread,
Jul 13, 2026, 11:19:41 PM (11 days ago) Jul 13
to lu...@googlegroups.com
Congrats, BTW at the top of my reply I meant to say "dynamic arrays" not
"associative arrays".

-- Jure
Reply all
Reply to author
Forward
0 new messages