This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Duster's profile picture

concentrating strings and booliens

Started by Duster, 09 April 2016 - 12:20 AM
Duster #1
Posted 09 April 2016 - 02:20 AM
i have

print("hello" .. string)
but it outputs startup:55: attempt to concentrate string and boolean
Lyqyd #2
Posted 09 April 2016 - 02:28 AM
Well, you're going to need to post the rest of your code, because the string library, in its natural state, is a table.
Lupus590 #3
Posted 09 April 2016 - 02:28 AM

tostring(true) -> "true"

does this help?
Dog #4
Posted 09 April 2016 - 02:29 AM
I'm not sure what your question is. Is your goal to concatenate a string and a boolean or are you wondering why you're getting that error message.

If you're trying to concatenate a string and a boolean - you can't do that - you need to tostring the boolean first, like so…

print("hello" .. tostring(string))

If you're asking why you're getting that error, it's because somewhere in your code you're setting your variable named string to either true or false. Post your code and we can help further.

EDIT: Double :ph34r:/> 'd

EDIT2: Also, don't name your variable 'string' - that disables the string API until you reboot
Edited on 09 April 2016 - 12:32 AM
Duster #5
Posted 09 April 2016 - 11:35 AM
I'm not sure what your question is. Is your goal to concatenate a string and a boolean or are you wondering why you're getting that error message.

If you're trying to concatenate a string and a boolean - you can't do that - you need to tostring the boolean first, like so…

print("hello" .. tostring(string))

If you're asking why you're getting that error, it's because somewhere in your code you're setting your variable named string to either true or false. Post your code and we can help further.

EDIT: Double :ph34r:/> 'd

EDIT2: Also, don't name your variable 'string' - that disables the string API until you reboot

that was just an example heres my code


term.clear()
term.setCursorPos(1,1)
print("Dust Os")
print("SmartStore 1.0")
x = 1
y = 1
  
m = peripheral.find("monitor")
m.setTextColor(colors.yellow)
 
function slow(text, speed) -- slow("Test Text!", 0.2)
  for x=1,string.len(text) do
    char = string.sub(text,x,x)
    m.write(char)
    sleep(speed)
  end
end
function down()
  x = 1
  y = y + 1
 
  m.setCursorPos(x,y)
end
 

d1 = peripheral.wrap("drive_6")
d2 = peripheral.wrap("drive_5")
m.clear()
m.setCursorPos(1,1)
m.setTextScale(3)
m.setBackgroundColor(colors.black)
m.setTextScale(.5)
m.setCursorBlink(true)
slow("Status:", 0.2)
down()
sleep(1)

d1Stat = {d1.isDiskPresent(), d1.getDiskLabel(), d1.hasData()}
d2Stat = {d2.isDiskPresent(), d1.getDiskLabel(), d1.hasData()}
if d1Stat[1] then
  m.setTextColor(colors.green)
  slow("Disk 1 Present", .2)
  down()
  m.setTextColor(colors.yellow)
  if d1Stat[2] == nil then
    m.setTextColor(colors.red)
    slow("Label: Nil", .2)
  else
    m.setTextColor(colors.yellow)
    slow("Label: " .. d1Stat[2], .2)
  end
  down()
  slow("Has Data?: " .. d1Stat[3], .2)
  down()
else
  m.setTextColor(colors.red)
  slow("Disk 1 Missing", .2)
  down()
  m.write("Nil")
  down()
  m.write("Nil")
  down()
  m.write("Nil")
end

Pastebin
InDieTasten #6
Posted 09 April 2016 - 12:41 PM
In your d1Stat table, you've got the result of d1.hasData(), which returns a boolean value, thats inserted in your table. When concatenating for the output for the use of slow, you effectively try, what the error message says. Just put slow("Has Data?"..tostring(d1Stat[3]), .2) and you should be good to go.
Edited on 09 April 2016 - 10:42 AM