Reputation: 119
So I have this Lua script :
function dispTanks()
mon.setCursorPos(offsetPos, 1)
mon2.setCursorPos(offsetPos,1)
for i=1, #machines do -- RC Tanks
--------------------------------------------
if string.find(machines[i], "rcirontankvalvetile")
or
string.find(machines[i], "rcsteeltankvalvetile") then
if peripheral.isPresent(machines[i]) then
periph = peripheral.wrap(machines[i])
fluidRaw, fluidName, fluidAmount, fluidCapacity, fluidID = marik.getTank(periph)
if fluidName == nil then
-- does not display empty tanks
elseif fluidName ~= nil then
mon2.setTextColor(tc)
x,y = mon2.getCursorPos()
mon2.setCursorPos(offsetPos, (y+1))
mon2.clearLine()
-- marik.cString(offsetPos,(y+1), tc, right, " ")
nameFL = split(marik.comma(fluidName), " ")
nameFL = nameFL[0]
mon2.write("Tank (" .. nameFL .. ") : " .. marik.getBuckets(fluidAmount) .. " buckets")
end
end
end
end
end
Now it gives a error at this line :
nameFL = split(marik.comma(fluidName), " ")
The error is: attempt to call nil
.
Now, I am a beginner in Lua and this isn't my script but a free to use script and I have no idea how to fix this.
EDIT
So before I added the split section this was the result the script should give :
The problem was I wanted to change the names ( ardite.molten ) to Ardite and a friend said I needed to use split, so I added the following :
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
and
nameFL = split(fluidName, " ")
nameFL = nameFL[0]
And changed : mon2.write("Tank (" .. marik.comma(fluidName) .. ") : " .. marik.comma(fluidAmount) .. " / " .. marik.comma(fluidCapacity) .. " mb (" .. marik.getBuckets(fluidAmount) .. " buckets)")
to : mon2.write("Tank (" .. nameFL .. ") : " .. marik.getBuckets(fluidAmount) .. " buckets")
which gives me the error :
Upvotes: 2
Views: 3498
Reputation: 23257
Either the split
function does not exist or the comma
function of marik
EDIT:
What I think what you try to do is get everything before the dot instead of the full name right?
In that case you can do this:
replace these lines
nameFL = split(marik.comma(fluidName), " ")
nameFL = nameFL[0]
with this:
nameFL = marik.comma(fluidName):match("[^.]*")
You don't need a split for this. what this does is pattern matching and in this case it matches to everything until the first dot
Upvotes: 4
Reputation: 3849
I don't believe lua has a built in split
function, and it needs to be defined yourself. Since you say you got this script from an external source, they may have defined it elsewhere.
Try reading this page for some ideas: http://lua-users.org/wiki/SplitJoin
If split is indeed defined, then the only other possibility is that the comma
function is undefined, in which case you would need to define it inside marik
.
Upvotes: 3