htv04/wiilove

for some reason, this script restarts my homebrew channel:

Closed this issue · 11 comments

function love.load()
    frames = {}

    for i = 1, 4 do
        table.insert(frames, love.graphics.newTexture("kris" .. i .. ".png"))
    end

    currentFrame = 1
    wiimote = love.wiimote.getWiimotes()[1]
    y = 100
end

function love.update(dt)
    currentFrame = currentFrame + dt;
    if currentFrame >= 5 then
        currentFrame = 1
    end
    if wiimote:isDown("down") then
        y += 50;
    end
end

function love.draw()
    if wiimote:isDown("down") then
        love.graphics.draw(frames[math.floor(currentFrame)], 100, y, 0, 1, 1, 48, 48)
    else
        love.graphics.draw(frames[1], 100, y, 0, 1, 1, 48, 48)
    end
end

title says it all. btw, i think a discussions page would be really helpful so nobody has to post every single coding issue they have in the issues page.

htv04 commented

I think I need more info. What does your file structure look like?

I have my images (kris(number).png) in data folder with main.lua. That's about it.

htv04 commented

Looking at your code again, I think you missed a tostring() statement on line 5. It should read like this:

for i = 1, 4 do
    table.insert(frames, love.graphics.newTexture("kris" .. tostring(i) .. ".png"))
end

The error shouldn't return to the homebrew menu though, it should just show the normal error screen. See if this helps anyway.

I have my images (kris(number).png) in data folder with main.lua. That's about it.

kris????

While I really have no say in this at all, its usually a good idea to keep stuff like this serious, but again this is just my two cents.

Looking at your code again, I think you missed a tostring() statement on line 5.

Concatenation should work automatically with numbers in Lua without needing a string converter, since that behaviour is defined in the Lua docs:

Lua denotes the string concatenation operator by ".." (two dots). If any of its operands is a number, Lua converts that number to a string.

Doing

the = 1
theThing = "the thing "
print(theThing + the)

Gives the error main.lua:3: attempt to perform arithmetic on a string value
doing tostring(the) does not give this error

htv04 commented

Looking at your code again, I think you missed a tostring() statement on line 5.

Concatenation should work automatically with numbers in Lua without needing a string converter, since that behaviour is defined in the Lua docs:

Lua denotes the string concatenation operator by ".." (two dots). If any of its operands is a number, Lua converts that number to a string.

Interesting, might have to look into this more then.

doing tostring(the) does not give this error

String concatenation in Lua is more officially done with the double-dot syntax, as the issue author has done in their original code. The Lua interpreter I have installed currently outright rejects concatenation of strings with +, even when both variables are strings.

doing tostring(the) does not give this error

String concatenation in Lua is more officially done with the double-dot syntax, as the issue author has done in their original code. The Lua interpreter I have installed currently outright rejects concatenation of strings with +, even when both variables are strings.

ah ok cuz i swear the same thing happened with me with .. but ig i just got to used to writing tostring()

htv04 commented

Fixed in 2e7b7fe