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

Api Doesn't Load Via Resource Pack

Started by Kingdaro, 05 August 2013 - 10:54 AM
Kingdaro #1
Posted 05 August 2013 - 12:54 PM
So basically, I want to make a resource pack that inserts my arealib API into the rom/apis folder. When I set everything up, however, any computer I try to start up freezes and just outright refuses to load, giving me a blank screen with no error. The computer's texture shows the arrow, as if a program is looping without end.

Another small example API I made works fine, and is loaded automatically, and other users' APIs work without problems as well.

Here's the resource pack: https://dl.dropboxusercontent.com/u/8005323/rehosting/arealib.zip
And the API itself: http://pastebin.com/1ytHScab

I feel like I missed something somewhere that I was supposed to do or avoid in making this api, and I apologize if this is the case.
Grim Reaper #2
Posted 05 August 2013 - 02:11 PM
It sounds like some kind of issue with the terminal API rather than your loading of the resource pack. I've had a lot of issues when working with the terminal API and a blank screen with no error is pretty common :P/>.

An error I found in the function area:fill is you're passing a y parameter to target.setCursorPos which is nil. You forgot to access the self.y value and used just y instead :P/>.


function area:fill()
	local line = string.rep(' ', self.width)
	target.setBackgroundColor(self.color)

	for y=self.y, self.y + self.height - 1 do
		-- Right here.
		target.setCursorPos(self.x, y)
		target.write(line)
	end

	return self
end

Other than that, you might want to check over your code for simple syntax errors which might cause an error to be thrown when the API is being loaded. Especially potential errors regarding manipulating the terminal API.

However, it still might be related to the resource pack although I don't see anything out of the ordinary with it.
Kingdaro #3
Posted 05 August 2013 - 02:37 PM
The API by itself loads normally without a resource pack, and works fine in use, so I pretty much ruled out any syntax or logic errors. As for what you've pointed out, the y there is the y in the for loop. It takes a line, and prints it the amount of times equivalent to the area's height.

for y=self.y, self.y + self.height - 1 do

And yeah, I figured it had something to do with using the term API, but it's not targeted towards using just the terminal. By that logic, setting the local "target" variable to nil would work, because the API would have nothing to do with term, but I've tried that, sadly.
Grim Reaper #4
Posted 06 August 2013 - 01:59 AM
After some testing, I think I know the problem.

You're setting the variable color within the local table 'area' to white in the colors table. However, since your API name starts with 'a', it loads before APIs whose name is further on in the alphabet. Therefore, when you try to access the colors API, it hasn't been loaded and therefore throws an error because you're trying to index a nil value.

TLDR: APIs load in alphabetical order, so arealib loads before colors and throws an 'attempt to index ? a nil value' error when you try to set area.color to colors.white; the table 'colors' is nil because the colors API hasn't been loaded.

A simple, but poorly designed, solution would be to just set area.color to 32,768, but the value for colors.white might change in a future update.

P.S. Kirito kicks ass.
BlankWolf #5
Posted 06 August 2013 - 02:14 AM
You're setting the variable color within the local table 'area' to white in the colors table. However, since your API name starts with 'a', it loads before APIs whose name is further on in the alphabet. Therefore, when you try to access the colors API, it hasn't been loaded and therefore throws an error because you're trying to index a nil value.

TLDR: APIs load in alphabetical order, so arealib loads before colors and throws an 'attempt to index ? a nil value' error when you try to set area.color to colors.white; the table 'colors' is nil because the colors API hasn't been loaded.

A simple, but poorly designed, solution would be to just set area.color to 32,768, but the value for colors.white might change in a future update.
Oh man thanks. I hade the same problem and I could n't figure out what the problem was.
Now it works fine. Thanks again =D
Kingdaro #6
Posted 06 August 2013 - 10:05 AM
After some testing, I think I know the problem.

You're setting the variable color within the local table 'area' to white in the colors table. However, since your API name starts with 'a', it loads before APIs whose name is further on in the alphabet. Therefore, when you try to access the colors API, it hasn't been loaded and therefore throws an error because you're trying to index a nil value.

TLDR: APIs load in alphabetical order, so arealib loads before colors and throws an 'attempt to index ? a nil value' error when you try to set area.color to colors.white; the table 'colors' is nil because the colors API hasn't been loaded.

A simple, but poorly designed, solution would be to just set area.color to 32,768, but the value for colors.white might change in a future update.

P.S. Kirito kicks ass.

Holy shit, you're a genius! Thank you so much!

And yes, he does. :P/>

EDIT: I do believe I'd be able to use the colors table if I set an area's color on object creation, and not on API creation, so I just threw "self.color = colors.white" under area:init().
Grim Reaper #7
Posted 06 August 2013 - 01:09 PM
I do believe I'd be able to use the colors table if I set an area's color on object creation, and not on API creation, so I just threw "self.color = colors.white" under area:init().

Great idea! :)/>