Search found 243 matches

by MrFariator
Tue Mar 02, 2021 5:36 pm
Forum: Support and Development
Topic: while and repeat loops still cause errors
Replies: 10
Views: 2543

Re: while and repeat loops still cause errors

I don't think that's exactly a good use case for repeat-until loops. You'd rather just have some basic control flow (or callbacks, whatever suits the situation) so the entire game doesn't come to a screeching halt just to process a key stroke. Remember, if you have an infinite loop in love.update, y...
by MrFariator
Tue Mar 02, 2021 6:53 am
Forum: Support and Development
Topic: Noob at classes: how to instantiate?
Replies: 3
Views: 1200

Re: Noob at classes: how to instantiate?

This is a simple mishap with the 'self' keyword. inputperceptron = {} inputperceptron.__index = inputperceptron function inputperceptron:new(o) o = o or {} setmetatable(o,self) o.weight = {} -- set weight[1] and [2] and [3] to random values for this perceptron o.weight[1] = math.random(1,10) o.weigh...
by MrFariator
Sun Feb 28, 2021 7:19 pm
Forum: Support and Development
Topic: game: crashes; I: need answers
Replies: 7
Views: 1512

Re: game: crashes; I: need answers

In main.lua, you have the following code: function ccol(a) if a.y + a.height == 600 then return true else return false end end function love.update(dt) while not ccol(q,c) do yspeed = yspeed + a * dt a = a^10 * dt end end This code assumes that the object a received by ccol() has fields a.y and a.he...
by MrFariator
Sun Feb 28, 2021 4:21 pm
Forum: Support and Development
Topic: game: crashes; I: need answers
Replies: 7
Views: 1512

Re: game: crashes; I: need answers

To add to darkfrei's answer, there's two main "falsy" values in lua: false, and nil (the absence of a value). So long the condition (in your case, simply the variable x) evaluates to anything that is non-false or non-nil, the while loop will continuously run forever (because the variable x...
by MrFariator
Sat Feb 27, 2021 9:20 am
Forum: Support and Development
Topic: Using an older love version gives out a black screen
Replies: 6
Views: 1582

Re: Using an older love version gives out a black screen

As darkfrei said, the range love.graphics.setColor uses was changed from 0-255 to 0-1 in version 11.0 of löve . In order to run your code in an older version, you could add this code snippet, in main.lua or elsewhere: local originalSetColor = love.graphics.setColor love.graphics.setColor = function ...
by MrFariator
Thu Feb 25, 2021 2:58 am
Forum: Support and Development
Topic: Attempt to index local 'self' (a number value)
Replies: 10
Views: 2118

Re: Attempt to index local 'self' (a number value)

Yeah, that's what the error traceback is good for. It will give you the chain of function calls that led to the error, and often in errors like this it's simply the previous step. Like the error you posted signals that line 21 in your state/level.lua might be the source, because it's the last place ...
by MrFariator
Wed Feb 24, 2021 9:27 pm
Forum: Support and Development
Topic: Attempt to index local 'self' (a number value)
Replies: 10
Views: 2118

Re: Attempt to index local 'self' (a number value)

You can access the score with self.score, that's perfectly fine. But you need to be mindful of how you invoke the function. To further drill the point, consider the following: function Score.update(self, amount) self.score = self.score + amount -- the 'self' is explicitly passed as the first paramet...
by MrFariator
Wed Feb 24, 2021 6:19 pm
Forum: Support and Development
Topic: Attempt to index local 'self' (a number value)
Replies: 10
Views: 2118

Re: Attempt to index local 'self' (a number value)

If you want to create multiple score tracking objects (assuming a OOP approach, like OP's code), you could do something along the lines of: -- score.lua local Score = {} Score.__index = Score function Score.new ( initialScore ) local newScoreTracker = {} newScoreTracker.score = initialScore or 0 set...
by MrFariator
Wed Feb 24, 2021 12:43 pm
Forum: Support and Development
Topic: Attempt to index local 'self' (a number value)
Replies: 10
Views: 2118

Re: Attempt to index local 'self' (a number value)

This is a mix up between the dot (.) and colon (:) syntax. Consider the following: function Score.load(self) self.score = 0 end Score.load(Score) -- is syntactically equivalent to function Score:load() self.score = 0 end Score:load() When you use the colon syntax, you are implicitly sending the tabl...
by MrFariator
Mon Feb 15, 2021 3:10 pm
Forum: Support and Development
Topic: % over math.fmod for IEEE remainder not working
Replies: 1
Views: 1214

Re: % over math.fmod for IEEE remainder not working

This is more of an implementation detail with lua (and luajit), than it is with löve. I believe this lua mailing list post might be relevant.