need help !

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.
neku
Prole
Posts: 3
Joined: Thu May 17, 2018 3:07 pm

Re: need help !

Post by neku » Mon May 21, 2018 7:24 pm

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

User avatar
zorg
Party member
Posts: 2410
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: need help !

Post by zorg » Mon May 21, 2018 7:58 pm

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.

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
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.
Me and my stuff :3True 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.

User avatar
pgimeno
Party member
Posts: 1337
Joined: Sun Oct 18, 2015 2:58 pm

Re: need help !

Post by pgimeno » Tue May 22, 2018 3:27 am

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.

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
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

neku
Prole
Posts: 3
Joined: Thu May 17, 2018 3:07 pm

Re: need help !

Post by neku » Thu May 24, 2018 9:17 am

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.

PGUp
Citizen
Posts: 69
Joined: Fri Apr 21, 2017 9:17 am

Re: need help !

Post by PGUp » Fri May 25, 2018 8:11 am

zorg wrote:
Wed May 16, 2018 11:27 am
Also, math.random(2) == 1 is just shorthand for if a random number is even, or odd; lua can do (condition) and ifTrue or ifFalse type branches; it will either return -100 or 100; the second one returns a number between -50 and 50.
Is there any documentation about this? I wanna know more.
-

User avatar
zorg
Party member
Posts: 2410
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: need help !

Post by zorg » Fri May 25, 2018 8:11 pm

PGUp wrote:
Fri May 25, 2018 8:11 am
zorg wrote:
Wed May 16, 2018 11:27 am
Also, math.random(2) == 1 is just shorthand for if a random number is even, or odd; lua can do (condition) and ifTrue or ifFalse type branches; it will either return -100 or 100; the second one returns a number between -50 and 50.
Is there any documentation about this? I wanna know more.
I mean, it's not rocket science :P
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.
(I wrote the above stuff from head, so i might have gotten some of it wrong; experiment and look stuff up yourself as well. :awesome: )
Me and my stuff :3True 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests