htv04 / wiilove

Framework for making 2D Nintendo Wii homebrew games in Lua
GNU Lesser General Public License v3.0
66 stars 8 forks source link

for some reason, this script restarts my homebrew channel: #2

Closed ACIDULATED closed 2 years ago

ACIDULATED commented 2 years ago
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 2 years ago

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

ACIDULATED commented 2 years ago

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

htv04 commented 2 years ago

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.

AM7999 commented 2 years ago

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

kris????

Lazr1026 commented 2 years ago

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.

TaiAurori commented 2 years ago

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.

GuglioIsStupid commented 2 years ago

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 2 years ago

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.

TaiAurori commented 2 years ago

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.

GuglioIsStupid commented 2 years ago

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 2 years ago

Fixed in 2e7b7fe19fe47d7f616949db771b2813ff62af8f