This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Please Help
Started by Dawscool2004, 27 March 2016 - 11:53 AMPosted 27 March 2016 - 01:53 PM
I am making an RPG at the moment (Code Here: http://pastebin.com/X6XhG8MG) and I am getting the error: rpg:50: Expected image, x, y Can you help please? There are files in /assets and /saves. Also, I am using flib
Posted 27 March 2016 - 02:00 PM
I'd start out by manually checking to see whether type(image) ~= "table" or type(x) ~= "number" etc, before the offending paintutils.drawImage() call - have the script print out which variables are at fault if any fail their checks. That'll give you a clue as to whether you should be checking that the image could be loaded, or whether you should be checking that x/y are coming in with valid values.
Mind you, it looks like you're constantly loading the "background" from the disk - why not do it once and keep it in RAM, saving disk / processor time?
Mind you, it looks like you're constantly loading the "background" from the disk - why not do it once and keep it in RAM, saving disk / processor time?
Posted 27 March 2016 - 03:41 PM
Thanks for the quick reply :)/>
Anyway, I put some checks into the redraw function(The one with the offending paintutils.drawImage() call) and it made no difference. I made it error anytime there was an incorrect type in the arguments and it never errored. Also, I don't know what you mean by 'checking that the image could be loaded'.
About the constantly loading background from disk, I plan to have multiple .nfp files that I would load into the variable background, so that wouldn't be an option as far as I'm aware.
Anyway, I put some checks into the redraw function(The one with the offending paintutils.drawImage() call) and it made no difference. I made it error anytime there was an incorrect type in the arguments and it never errored. Also, I don't know what you mean by 'checking that the image could be loaded'.
About the constantly loading background from disk, I plan to have multiple .nfp files that I would load into the variable background, so that wouldn't be an option as far as I'm aware.
Posted 28 March 2016 - 08:09 AM
Well, if type(background) ~= "table" then that'd tell you that for whatever reason, paintutils.loadImage() failed to load the image file. For example, if it can't locate the file using the specified path, it'll return nil - which drawImage() will later choke on.
If your type checks aren't catching an error but paintutils is, then there's a problem with your checks. Here's a more detailed example as to how they might be done:
If your type checks aren't catching an error but paintutils is, then there's a problem with your checks. Here's a more detailed example as to how they might be done:
if image ~= nil then
local background = paintutils.loadImage(image)
if type(background) ~= "table" or type(x) ~= "number" or type(y) ~= "number" then
error("Invalid args! img = "..tostring(image).." bg = "..type(background).." x = "..type(x).." y = "..type(y))
end
paintutils.drawImage(background, x, y)
end
Posted 28 March 2016 - 10:07 AM
Okay, so I added the checks you suggested and two things happened(The first one is probably unrelated): When I opened the rpg, there was no error and the screen was just green instead of the background image. The second thing is that it errored. I just realised as I was typing this that the image I was trying to draw was '/assets/city01' instead of '/assets/city01.nfp'. I fixed that and now I get the error: bios.lua:171: bad argument: string expected, got nil. Pastebin link: pastebin.com/NbCQNUxq
Posted 28 March 2016 - 10:35 AM
bios.lua changes a bit from version to version; this is probably pretty close to whatever copy of ComputerCraft you've got is using.
Line 171 is part of the write() function declaration, so at some point you're trying to write a variable that hasn't actually been defined.
Do a search of your script for every instance where you call write() and are passing in a variable that might not be defined. Put another type check above each of those lines, primed to throw a unique error if type(var) == "nil". Once you know which one is undefined you'll more easily be able to figure out why.
Line 171 is part of the write() function declaration, so at some point you're trying to write a variable that hasn't actually been defined.
Do a search of your script for every instance where you call write() and are passing in a variable that might not be defined. Put another type check above each of those lines, primed to throw a unique error if type(var) == "nil". Once you know which one is undefined you'll more easily be able to figure out why.
Edited on 28 March 2016 - 08:36 AM
Posted 28 March 2016 - 03:15 PM
I added one check, and immediately found out what variable was nil. The variable's name is 'cLocation'. Believe it or not, all images in the game are now just replaced with green. I'm going to do some testing with the redraw function. I have tested loading the images in another program, and they loaded fine.