hi pgimeno
and thanks for the suggestion. I found a few solutions (in various sources). they look like "hump.timer". I even got two of them (wait & sleep) up and running. But I can not manage it in my app so it works here too. I am afraid that the love2d (although I like it very much) with its features (as a game engine) is not very suitable for non-game apps.
one would have to slow down the function "love.update (dt)" as desired resp. can switch off completely. I have not investigated how it works with the function "love.draw ()". I have no experience with game engines until now.. love2d is the first. Besides that, my programming skills are rather modest. please excuse my google english.
here you can see what i mean by slowing down .. showing the individual jumps. that's all.
https://en.wikipedia.org/wiki/Knight%27s_tour
need help !
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: need help !
Löve is somewhat suitable for non-game applications; to be blunt about it, it's not the framework's fault you don't have the necessary knowledge to write something in it.
You don't need to "slow down" love.update, you need to learn what dt is, and how to use it.
dt is basically the amount of time passed since the last call to love.update (the simplest explanation, of course there are other things that happen but i'm not gonna explain since you don't need to care about those).
So, if you want to do a knight's tour and draw, like, one step each second, then you need to call a function once per second.
You don't need to care how many times the drawing part will happen, as long as you store the information about the current, and possibly the previously visited squares, in a table, for example.
You don't need to "slow down" love.update, you need to learn what dt is, and how to use it.
dt is basically the amount of time passed since the last call to love.update (the simplest explanation, of course there are other things that happen but i'm not gonna explain since you don't need to care about those).
So, if you want to do a knight's tour and draw, like, one step each second, then you need to call a function once per second.
Code: Select all
local delay = 1.0 -- seconds
local timer = 0.0
function love.update(dt)
timer = timer + dt
if timer > delay then
-- call function that calculates next step of the knight's tour algorithm
end
end
function love.draw()
-- draw the chessboard and the squares already visited by the algorithm.
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: need help !
You still need to draw the board. Here's an example of how to use hump.timer. In this example, the board is drawn in a very simple way, with an 1 in the grid drawing a filled rectangle, and a 0 in the grid drawing a rectangle border.
In the example, the moves that are generated just consist of advancing one square in a loop. When it finishes, it starts again.
In the example, the moves that are generated just consist of advancing one square in a loop. When it finishes, it starts again.
Code: Select all
local timer = require 'hump.timer'
local love = require 'love'
function love.update(dt)
timer.update(dt)
end
local t = {}
timer.script(function(wait)
for i = 1, 64 do t[i] = 0 end
repeat
for y = 0, 7 do
for x = 0, 7 do
t[y*8+x+1] = 1
wait(.05)
t[y*8+x+1] = 0
end
end
until false
end)
function love.draw()
for y = 0, 7 do
for x = 0, 7 do
local r = 30
love.graphics.rectangle(t[y*8+x+1]==1 and "fill" or "line",
x*r, y*r, r, r)
end
end
end
function love.keypressed(k) if k == "escape" then return love.event.quit() end end
Re: need help !
hi pgimeno
hi zorg
thanks for the suggestions. I will study them and hope that I can understand and apply them (sometime). At the moment I am quite overstrained. I'm afraid that my code has to be totally different.
hi zorg
thanks for the suggestions. I will study them and hope that I can understand and apply them (sometime). At the moment I am quite overstrained. I'm afraid that my code has to be totally different.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: need help !
I mean, it's not rocket science
The lua docs might have some sparse mentions of this, but basically, it's just a quick alternative to if-then-else (and a few other things) with a few caveats.
Code: Select all
-- falsy means false or nil, everything else is truthy
return A or B -- if A is falsy then return B
return A and B -- if A is truthy then return B
return A and B or C -- if A is truthy then return B, else return C; B must not be falsy, or this won't work.
-- if A,B,C are function calls, they are lazily evaluated.
return A and B() or C() -- B only called if A was truthy, C only called if A was falsy.
return A or DEFAULT -- common idiom if the value in A can be nil (and we're not expecting false there) and you want a default value in such a case.
return A and B or (C and D or (E and F or (...))) -- the correct parenthesization of this logic structure.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Google [Bot] and 1 guest