You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to make a conditional piece of snippet that prints node 2 inside node 3, if node 1 is given an year older than 2007. The issue seems to be the function tonumber returning nil from the get-go. If I remove tonumber I get "trying to compare a string to a number" error, which makes sense. I am very much a beginner at Lua, and even though I have a hunch that the problem might be tonumber being evaluated when the snippet expands (node 1 still lacking a input), I have no idea how to fix it (if that is indeed the issue). Could the more experienced, please, give me some ideas?
eprint_format=function(args)
localyear=tonumber(args[2][1])
localeprintclass=args[1][1]
ifyear==nilthenreturnsn(nil, { t('not working') })
elseifyear<2007thenreturnsn(nil, { t(eprintclass..'/') })
elsereturnsn(nil, { t('') }) -- If the year is not smaller than 2007, insert nothingendendendreturn{
s({
trig='eprint',
name='testing conditional',
desc='expands to subsnippet',
snippetType='autosnippet'
},
fmta([[year = {<>},eprintclass = {<>},eprint = {<><>},]], { i(1), i(2), d(3, eprint_format, { 1, 2 }), i(4) })
),
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Dear all,
I am trying to make a conditional piece of snippet that prints node 2 inside node 3, if node 1 is given an year older than 2007. The issue seems to be the function
tonumber
returningnil
from the get-go. If I removetonumber
I get "trying to compare a string to a number" error, which makes sense. I am very much a beginner at Lua, and even though I have a hunch that the problem might betonumber
being evaluated when the snippet expands (node 1 still lacking a input), I have no idea how to fix it (if that is indeed the issue). Could the more experienced, please, give me some ideas?Beta Was this translation helpful? Give feedback.
All reactions