I need help with a function I'm writing it is suppose to draw a circle around the player relative to my mouse and when I try to make it a specific distance away from the player it is being weird. Please also note that I'm bad at spelling and some words in my code my be misspelled.
When you are creating table (return { … }), you can not reference keys or values in that table, as you are just creating it. Move the Distance = … outside before that return. And if you want to return also Distance, just add Distance = Distance in that table.
P.S.: please use support and development forum instead of ports forum. Ports forum is for things about porting love to other platforms, not about general problems
Itswolfcity811 wrote: ↑Tue Jun 27, 2023 12:46 am
I need help with a function I'm writing it is suppose to draw a circle around the player relative to my mouse and when I try to make it a specific distance away from the player it is being weird. Please also note that I'm bad at spelling and some words in my code my be misspelled.
local function newWeapon (player, weapons, id, distance)
id = id or 1
-- local weapon = weapons[id] -- why you have weapons here?
print(player.x, player.y, player.radius),
print(distance),
print(distance + player.radius),
local distance = distance + player.radius
return {
id = id,
distance = distance,
player = player, -- to access for draw function
draw = function(self)
love.graphics.circle("fill", self.player.x + self.distance, self.player.y + self.distance, self.player.radius / 10)
end,
}
end
return newWeapon