Log In  


I have been attempting to make a Picotron game. When there are too many objects in a table that are being updated, some objects just do not update. I really don't know if this is a problem on my end or a Picotron bug.

I have falling rocks from the sky (as it is a sequel to Rockfall 3), and when there are maybe 10-20 of them at once, they will collectively pause in the air before continuing. The player movement does not turn choppy, and the CPU usage stays quite low (15% with about 100 rocks), so I don't think it's an optimization problem.

Here's the code in my rocks.lua:

rocks = {}

function add_rock(x,y,xv,yv)
	add(rocks, {
		x=x,
		y=y,
		xv=xv,
		yv=yv
	})
end

function add_rock_master()
	add_rock(rnd(464),-rnd(32)-8,0,0)
end

function update_rocks()
 	for i,r in pairs(rocks) do
		r.x += r.xv
		r.y += r.yv

		r.yv += grav
		r.yv /= wind_res

		if r.y > 270 then
			add_rock_master()
			del(rocks,r)
			break
		end
	end
end

function draw_rocks()
	for i,r in pairs(rocks) do
		sspr(5,0,0,8,8,r.x,r.y,16,16)
	end

And in my main.lua

-- Rockfall 4
-- SealProgrammer

include "player.lua"
include "constants.lua"
include "rocks.lua"

add_players(7)
add_rock_master()

window{
	cursor = 0
}

screen = 0

function _update()
	if screen == 0 then
		screen = 1	
	elseif screen == 1 then
		update_rocks()
		update_players()

		if flr(rnd(120)) == 0 then
			add_rock_master()
		end
	end
end

function _draw()
	cls(12)
	map()
	draw_players()
	draw_rocks()
	print(stat(1))
end

If there's any other relevant code I can provide it, but it's probably easier to just load the cart.

Last, here's the cartridge:

Cart #weirdrockstuffpleasehelpthanks-0 | 2024-07-22 | Embed ▽ | License: CC4-BY-NC-SA

It can be loaded with load #weirdrockstuffpleasehelpthanks.

Thanks everyone. I really don't know how I can fix it.

EDIT: I think it is tied to when new rocks are created. I switched it out to spawn a couple of new rocks in a wave, and not delete the old ones, and it gets the jitters only when new rocks are being added.



1

Figured it out, I had a break statement that meant that whenever a rock was respawned, it would stop all the rocks after it from updating.



[Please log in to post a comment]