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

Unfinished string

Started by Jazza, 06 July 2012 - 09:43 AM
Jazza #1
Posted 06 July 2012 - 11:43 AM
Hey there, I can't figure this out at all o.O

I get error:

Bios:206: [string "startup"]:13: unfinished string

I have actually modified the code, but it says the line the first print is on has an error.


-- UpSideDownOS - V.0.0.1 - Jazza_Hat

function clear()
term.clear()
term.setCursorPos(1, 1)
end

function screen( ... )
tArgs = { ... }

print("/------------")

if #tArgs =>2 then
  for i = 0, #targs, 1 do
  write(tArgs)
  end
else tArgs == false then
   comment = "Welcome to UpSideDownOS V.0.0.1!"
  end
print("|			 |")
print("-------------/")
end
end
clear()
screen()

Also, if you could improve it, that would be great too.
Thanks,
Jazza
Luanub #2
Posted 06 July 2012 - 12:53 PM
You've got tArgs in the script a couple of different ways, remember lua is case sensitive. Make them all the same and you should be good.
Pinkishu #3
Posted 06 July 2012 - 01:14 PM
Hey there, I can't figure this out at all o.O

I get error:

Bios:206: [string "startup"]:13: unfinished string

I have actually modified the code, but it says the line the first print is on has an error.


-- UpSideDownOS - V.0.0.1 - Jazza_Hat

function clear()
term.clear()
term.setCursorPos(1, 1)
end

function screen( ... )
tArgs = { ... }

print("/------------")

if #tArgs =>2 then
  for i = 0, #targs, 1 do
  write(tArgs)
  end
else tArgs == false then
   comment = "Welcome to UpSideDownOS V.0.0.1!"
  end
print("|			 |")
print("-------------/")
end
end
clear()
screen()

Also, if you could improve it, that would be great too.
Thanks,
Jazza

Its about escape codes :P/>/>
You see in a string you might want to write things
like a new line or a "
Now you cannot write a " in a string of course since that would close the string

"blah "hello" meow" does not work
thats what theres escape codes for, the character starts an escape code

so this up there would be
"blah "hello" meow"

it escapes the inner " characters so they're not seen as closing the string but rather a character in the string
now acts as escape character
so your

print("/————")
is an unfinished string since the before the ending " escapes that ", so to lua it means you want to put a " into the string, not that you finish the string
So how do we resolve that? Well we want that special character to be just another character in the string, right? So we escape it!

print("/————")

not sure if that explanation makes sense
Jazza #4
Posted 06 July 2012 - 01:43 PM
^^Yea, I don't read things that great do I =P
^I just noticed that while reading another thread. I played around with it a bit more.


-- UpSideDownOS - V.0.0.1 - Jazza_Hat

function clear()
term.clear()
term.setCursorPos(1, 1)
end

function screen( ... )
tArgs = { ... }

if #tArgs >= 1 then
for i = 0, #tArgs, 1 do
write(tArgs[i])
end

elseif tArgs == null then
tArgs = "Welcome to UpSideDownOS V.0.0.1!"
end

print(tArgs)
end

clear()
screen(hi)

In theory it should print "hi". But my code is obviously wrong =/

It does however, if I leave the argument clear, print "Welcome to UpSideDownOS V.0.0.1!"

thanks for the help =D
MysticT #5
Posted 06 July 2012 - 05:13 PM
That's because hi is nil, your need to use "hi" to make it a string:

-- UpSideDownOS - V.0.0.1 - Jazza_Hat

function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

function screen( ... )
  tArgs = { ... }
  if #tArgs >= 1 then
    for i = 0, #tArgs, 1 do
	  write(tArgs[i])
    end
  elseif tArgs == null then
    tArgs = "Welcome to UpSideDownOS V.0.0.1!"
  end
  print(tArgs) -- this line would print: table: <some number>, if there's arguments. You may want to change that.
end

clear()
screen("hi")
Jazza #6
Posted 07 July 2012 - 11:06 AM
Hmm, could I set tArg[1] to another variable, maybe word1. I guess I could kinda save it to a table?