Jump to content




Getting "unable To Concatenate A Nil With A String"


  • You cannot reply to this topic
11 replies to this topic

#1 austinv11

  • Members
  • 107 posts

Posted 30 September 2013 - 08:19 PM

Please help, it has to do with the variable "playerName"

Here's the code
local DOOR_OPEN_DURATION = 2.5

local hour = os.time()

p = peripheral.wrap("right")

local doorSide = "top"
local logFilePath = "/doorOpenLog"

local function welcome()
  if playerName ~=  "Grand_Panda" or "MajorCooke" or "austinv11" then
    p.say("Welcome "..playerName.." to AustinCorp11")
	
  elseif playerName == "Grand_Panda" then
    p.say("Hey Panda, welcome to AustinCorp11 and have some Bamboo!")
  
  elseif playerName == "MajorCooke" then
    p.say("Salutes to the Major Cookie!")
  
  elseif playerName == "austinv11" then
    p.say("Welcome the owner of AustinCorp11!")
    sleep(0.5)
    p.say("*Claps")
    end
  end

local function logPlayerName (logFilePath, playerName)
  local fileHandle = fs.open ("/doorOpenLog", "a")

  if fileHandle then
    fileHandle.writeLine(playerName.." at "..hour)
    fileHandle.close()
  
    return true
  
    end
  
  return false
  end

local function openDoor()
  rs.setBundledOutput(doorSide, 0)
  sleep(DOOR_OPEN_DURATION)
  rs.setBundledOutput(doorSide, 1)
end

local function main (logFilePath)
  while true do
    local _, playerName = os.pullEvent("player")
  
    openDoor() 
    logPlayerName(logFilePath, playerName)
    welcome()
    p.say("Remember to finish the welcome() function!")
    end
  end

rs.setBundledOutput(doorSide, 1)
main()

Any response is appreciated, thanks!

#2 willwac

  • Members
  • 182 posts

Posted 30 September 2013 - 08:21 PM

At what line are you getting this error?

#3 austinv11

  • Members
  • 107 posts

Posted 30 September 2013 - 08:23 PM

line 12, but it doesn't recognize my username (austinv11) and use my own specific welcome

#4 willwac

  • Members
  • 182 posts

Posted 30 September 2013 - 08:28 PM

View Postaustinv11, on 30 September 2013 - 08:23 PM, said:

line 12, but it doesn't recognize my username (austinv11) and use my own specific welcome

Are you using MiscPeripherals Player Detector?
Did you try making the program in the lua shell?

Just a post of mine
http://www.computerc...o-use-varibles/

#5 campicus

  • Members
  • 164 posts

Posted 30 September 2013 - 10:09 PM

It looks like it isn't setting any value to "playerName", which means that line 12 isn't the problem, this is:

local _, playerName = os.pullEvent("player")

I don't know anything about player detection though sorry

EDIT: Try defining the playerName outside of the function (at the beginning of your program)

#6 Inumel

  • Members
  • 120 posts

Posted 30 September 2013 - 11:06 PM

  if playerName ~=  "Grand_Panda" or "MajorCooke" or "austinv11" then
Shouldent that be
  if playerName ~=  "Grand_Panda" or playerName ~= "MajorCooke" or playerName ~= "austinv11" then
?

#7 Inumel

  • Members
  • 120 posts

Posted 30 September 2013 - 11:10 PM

Here ill post some code I use for a player detector door, It's probably not perfect but.. it works

http://pastebin.com/TLnJbvrM

Mine uses a table in order to get its allowed players, but that can be changed to your method if you prefer

It can help you figure out what you need to do to get your own working :)

#8 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 01 October 2013 - 01:02 AM

local _, playerName
"local" means that the following variables (in this case _ and playerName) are only visible inside the while loop.

#9 plazter

  • Members
  • 134 posts

Posted 01 October 2013 - 09:20 AM

wouldn't it be easier with a tabel like:

local whitelist = {
['name here'] = true,
}



and then if its not a whitelisted 1

if not whitelist[ playerName:lower() ] then
  print("Welcome ".. playerName .." to the corp")
elseif whitelist[ playerName:lower() ] then
  print("something")
end

just wondered :D

//Plazter

#10 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 01 October 2013 - 01:03 PM

View Postplazter, on 01 October 2013 - 09:20 AM, said:

wouldn't it be easier with a tabel like:

local whitelist = {
['name here'] = true,
}



and then if its not a whitelisted 1

if not whitelist[ playerName:lower() ] then
  print("Welcome ".. playerName .." to the corp")
elseif whitelist[ playerName:lower() ] then
  print("something")
end

just wondered :D

//Plazter
ehh.. Why do is the if the same as the elseif? 0.0
I think you meant something like:
local wl = {
   [ "playerName" ] = true
}

if wl[ player ] then -- Without the lower cuz names can contain upper characters
    print(string.format("Welcome %s!", player))
else
    print(string.format("Im sorry, you are not allowed here, %s :(/>", player))
end


#11 austinv11

  • Members
  • 107 posts

Posted 01 October 2013 - 08:03 PM

Thanks guys for the responses! Especially to Immibis, as his advice helped me the most!

#12 plazter

  • Members
  • 134 posts

Posted 02 October 2013 - 01:41 AM

View PostEngineer, on 01 October 2013 - 01:03 PM, said:

View Postplazter, on 01 October 2013 - 09:20 AM, said:

wouldn't it be easier with a tabel like:

local whitelist = {
['name here'] = true,
}



and then if its not a whitelisted 1

if not whitelist[ playerName:lower() ] then
  print("Welcome ".. playerName .." to the corp")
elseif whitelist[ playerName:lower() ] then
  print("something")
end

just wondered :D/>

//Plazter
ehh.. Why do is the if the same as the elseif? 0.0
I think you meant something like:
local wl = {
   [ "playerName" ] = true
}

if wl[ player ] then -- Without the lower cuz names can contain upper characters
    print(string.format("Welcome %s!", player))
else
    print(string.format("Im sorry, you are not allowed here, %s :(/>/>", player))
end

The lower() is easy'st if u ask me since you put the whole name in lowercase, atleast that my experiance :) btw "%s" what does that do?





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users