The LÖVE Blog (BLÖG?) also has some great techniques and such on it. I would recommend it.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Roland_Yonaba wrote:I use a similar trick, not not <value>, to convert any type to a boolean. A truthy value would return true, a falsy value would return false.
I can't think of anywhere that I've used this with the Love2D api but there have been times when something requests a Lua callback and passes that callback something not super useful. For example, the VBA lua scripting interface function for `memory.registerwrite` passes the memory address to the callback as opposed to the value written to the memory address. So having a function that proxies a better callback with that is passed the result of a common operation can result in much better function signatures.
function readbyte_proxy(callback)
return function(address)
callback(memory.readbyte(address), address)
end
end
function print_direction(direction)
print("direction", direction)
end
memory.registerwrite(memory_addresses.character_direction, readbyte_proxy(print_direction))
local isValidOryginal = {'text1','text2','text3'}
locla isValid = {}
for i=1, # isValidOryginal do -- every time isValidOryginal changes (once if it never changes)
isValid[isValidOryginal[i]] = true
end
isValidOryginal = nil -- optional if isValidOryginal never changes
--checking content:
if isValid['text1'] then --this is true
-- do stuff
end
if isValid['text4'] then-- this is nil (false)
-- do stuff
end