[SOLVED] Character doesn't appear

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
GoldenTCat
Prole
Posts: 7
Joined: Thu Dec 26, 2024 12:48 am
Location: Brazil

[SOLVED] Character doesn't appear

Post by GoldenTCat »

hello again, I'm having a problem where my game character isn't appearing and everything seems very strange because the functions and files don't return any type of error :( .

character draw code (humanModules.lua)

Code: Select all

function draw(p)
	local size = 3
	copyBody = {}
	
	for i=1, 6 do table.insert(copyBody, p.body[i]) end
	
	sort = function(a, b) return a.z < b.z end
	table.sort(copyBody, sort)
	
	print("--------- drawing body ---------") --no, that's not working
	for i, b in ipairs(copyBody)do
		print("drawing " .. b.name) 
		b.img:setFilter("nearest", "nearest")
		love.graphics.setColor(p.color)
		drawSprite(b.grid, b.img, p.pos.x, p.pos.y, size, size)
	end
end
function that draws all mobs (mobsModules.lua)

Code: Select all

function mobsDraw()
	for i, a in ipairs(mobs) do
		a.draw(a)
	end
end
main code (main.lua)

Code: Select all

require("resources/scripts/mobs/mobsModules")
require("resources/scripts/mobs/human/humanModules")

function love.load()
	love.graphics.setDefaultFilter("nearest", "nearest", 1)
	
	
	newHuman(nil, {100, 200, 0}, {1,1,1})
	newHuman(nil, {300, 300, 0}, {0.3,0.2,0.2})
	print("running without problems")
	
end

function love.update(dt)
	mobsUpdt(dt)
end

function love.draw()
	mobsDraw()
end
here is all the files
https://drive.google.com/file/d/1EbMAFK ... sp=sharing
Last edited by GoldenTCat on Mon Jan 06, 2025 7:16 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3710
Joined: Sun Oct 18, 2015 2:58 pm

Re: Character doesn't appear

Post by pgimeno »

You haven't provided enough code to be sure, but I'd bet that what is happening here is global clashing. If you define a global function called draw, as you do above, it's shared by all instances. If another file defines another global function called draw, it will overwrite the previous one.

My advice is to avoid globals like the plague.
User avatar
dusoft
Party member
Posts: 765
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Character doesn't appear

Post by dusoft »

Debug, debug and more debug (print values or in any other way). Put those in important places of your code. I am sure you will spot the issue. If not, then come back with a log.
GoldenTCat
Prole
Posts: 7
Joined: Thu Dec 26, 2024 12:48 am
Location: Brazil

Re: Character doesn't appear

Post by GoldenTCat »

dusoft wrote: Tue Dec 31, 2024 12:52 pm Debug, debug and more debug (print values or in any other way). Put those in important places of your code. I am sure you will spot the issue. If not, then come back with a log.
It was a simple error in which I placed the character's draw command in the update function. When I found out I felt really stupid :death: .
User avatar
dusoft
Party member
Posts: 765
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Character doesn't appear

Post by dusoft »

GoldenTCat wrote: Mon Jan 06, 2025 7:15 pm
dusoft wrote: Tue Dec 31, 2024 12:52 pm Debug, debug and more debug (print values or in any other way). Put those in important places of your code. I am sure you will spot the issue. If not, then come back with a log.
It was a simple error in which I placed the character's draw command in the update function. When I found out I felt really stupid :death: .
Yeah, that happens. In exceptional cases you can use graphics module functions out of love.draw, see:
https://love2d.org/wiki/love.graphics.present

I used this for example to display "loading" message already in love.load before love.draw function even kicks in.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests