2

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 :

enter image description here

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 :http://puu.sh/a51QI/a848facf1b.png

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Kev30
  • 119
  • 1
  • 9
  • 3
    You seem to be using ComputerCraft, which does have `marik.comma`, and so the problem is `split`. – lhf Jul 10 '14 at 11:58
  • lhf Yes i'm using computercraft. marik.comma is a include file in the program. because i normally used marik.comma(fluidName) inside the mon2.write( it worked but outside the mon2.write it isnt working. – Kev30 Jul 10 '14 at 12:00

2 Answers2

4

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

Ivo
  • 18,659
  • 2
  • 23
  • 35
  • `function firstToUpper(str) return (str:gsub("^%l", string.upper)) end ` This is the split function right? – Kev30 Jul 10 '14 at 11:54
  • that is not the split function. it's a firstToUpper function just as it says it makes the first letter of a string uppercase. – Ivo Jul 10 '14 at 12:01
  • ooooh my bad, so maybe a noobie question but how do i make a split function out of this? – Kev30 Jul 10 '14 at 12:04
  • It worked thanks! Now how do i use the firstToUpper function in it? – Kev30 Jul 10 '14 at 12:09
  • wrap it all in firstToUpper to make the first uppercase, so it would be `nameFL = firstToUpper(marik.comma(fluidName):match("[^.]*"))` – Ivo Jul 10 '14 at 12:10
  • Thanks that worked to! Now i forgot to ask something. Do u maybe know why i get double results? It only should show 1 of each and not 2. (so 1 ardite 1 cobalt etc) – Kev30 Jul 10 '14 at 12:12
  • can't help you with that – Ivo Jul 10 '14 at 12:17
  • 1
    Thank you for your help! I will make a new topic for that then. I flagged your post as answer! – Kev30 Jul 10 '14 at 12:18
3

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.

Cereal
  • 3,699
  • 2
  • 23
  • 36