6 posts
Posted 29 December 2012 - 03:26 PM
This has me completely confused it really looks like it should work the second argument appears to work but first one doesn't.
- local tArgs = { … }
- local x = 0
- local y = 0
- local z = 0
- local xSize = 0
- local zSize = 0
- local collected = 0
- local unloaded = 0
- local idle time = 0
- if #tArgs ~= 2 then
- print( "Usage: excavate <length>, <width>" )
- return
- end
- print(xSize)
- print(zSize)
- xSize = tonumber(tArgs[1])
- zSize = tonumber(tArgs[2])
- print(zSize)
- print(xSize)
When i run that code it throws an error and i dont understand why
[attachment=833:2012-12-28_20.13.44.jpg]
1111 posts
Location
Portland OR
Posted 29 December 2012 - 03:28 PM
remove the extra spaces in your concatenations.
print(xSize .. "\n")
--should be
print(xSize.."\n")
I'm not sure you need the \n print does one for you so this will add an extra line in between the print statements.
6 posts
Posted 29 December 2012 - 03:32 PM
Well i tired it like you said but it still throws the same error
1111 posts
Location
Portland OR
Posted 29 December 2012 - 03:41 PM
Try printing tArgs[1] and see what value it contains. For some reason it looks like the following line is assigning a nil value to xSize. Its weird because tArgs[2] appears to be transferring properly to zSize.
xSize = tonumber(tArgs[1]) --line that does not appear to be working
Try this for the debug prints
for x=1, #tArgs do
print("tArgs["..x.."] = "..tArgs[x].." and is type "..type(tArgs[x]))
end
6 posts
Posted 29 December 2012 - 03:51 PM
It seems that the comma is inserted into the first argument. Thanks for your help how are arguments separated in lua
8543 posts
Posted 29 December 2012 - 04:04 PM
The shell separates arguments by spaces.
6 posts
Posted 29 December 2012 - 04:07 PM
Thanks you guys for your help
2005 posts
Posted 29 December 2012 - 04:13 PM
Your line numbering does not appear to match the line numbering in the program which is throwing the errors.
212 posts
Location
Dallas, Tx
Posted 29 December 2012 - 04:33 PM
first off
if #tArgs ~= 2 then
should be something like this to print the usage when you dont have enough arguments
if #tArgs < 2 then
second i dont think you can return an empty argument
try
return nil
instead or returning nothing
return
EDIT:
i didnt even see this that you added a comma when you are trying to pass arguments to your program. the comma makes that a string not a number so when it tried to make a var a number when its a string with a alpha character in it its going to error out
1111 posts
Location
Portland OR
Posted 29 December 2012 - 04:37 PM
first off
if #tArgs ~= 2 then
should be something like this to print the usage when you dont have enough arguments
if #tArgs < 2 then
second i dont think you can return an empty argument
try
return nil
instead or returning nothing
return
if #tArgs ~= 2 then
Works just fine and so will the return.
However it is probably better to error the script then return. Personally I would do this, but its just a matter of personal preference, they both will work.
if #tArgs ~= 2 then
error( "Usage: excavate <length>, <width>" )
end
212 posts
Location
Dallas, Tx
Posted 29 December 2012 - 04:40 PM
i like to be very specific in my programs so i can deduct alot faster where i throw my errors
6 posts
Posted 29 December 2012 - 05:12 PM
Sorry I messed it up when i posted it here. My problem was the comma tried to use to seperate my arguements used to java i guess. I copied the try statement out of the excavate program which i am basing my program off of.
2005 posts
Posted 29 December 2012 - 08:12 PM
If your issue has been resolved, then all is well. But from what I can see here I do not know that to be the case.
If you are still getting an error, then open the program with edit and go to the line number specified in the error message. Highlight that line in your post.