Join us on Discord!
You can help CodeWalrus stay online by donating here.

TI Nspire Lua things

Started by Strontium, April 22, 2015, 11:06:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Strontium

I've been messing around with Lua on my TI Nspire, and made a thing that allows you to move a square around and draw a line when you press 6. The code, so far, is as follows:
player_pos = {100, 100}
atacking = false

function attackLeft()
    if attacking == false then
        attacking = true
    else
        attacking = false
    end
end

function on.arrowUp()
    player_pos[1] = player_pos[1] - 1
end

function on.arrowDown()
    player_pos[1] = player_pos[1] + 1
end

function on.arrowLeft()
    player_pos[2] = player_pos[2] - 1
end

function on.arrowRight()
    player_pos[2] = player_pos[2] + 1
end

function on.charIn(char)
    if char == "6" then
        attackLeft()
    end
end

function on.timer()
    platform.window:invalidate()
end

timer.start(0.1)

function on.paint(gc)
    gc:drawRect(player_pos[2], player_pos[1], 20, 20)
    if attacking == true then
        gc:drawLine(player_pos[2] + 20, player_pos[1] + 10, player_pos[2] + 75, player_pos[1] + 10)
    end
end


Its just a prototype I hacked together. Some things in it dont even make sense (for example, how I dealt with the player position). However, there is something I have a question about:

When I hold down any of the direction arrows, then press 6 to draw the line, the player stops moving in x direction. I know why this is, though, its because when I press 6 the program stops receiving input from the arrows. However, I want to be able to continue moving even after I press 6. How would I do this?

Edit: Also, is there a function that prevents the calc asking you if you want to save when you close out the application?
  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES

alexgt

Can't give you help as I don't know about Lua but I wish you luck, sorry :(
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Jonius7

Perhaps this is worth a try:

Use on.arrowKey(key) and then call it in your on.charIn(char)


function on.arrowKey(key)
    if key == "up" then
        player_pos[1] = player_pos[1] - 1
    end

    if key == "down" then
        player_pos[1] = player_pos[1] + 1
    end

    if key == "left" then
        player_pos[2] = player_pos[2] - 1
    end

    if key == "right" then
        player_pos[2] = player_pos[2] + 1
    end
end

function on.charIn(char)
    if char == "6" then
        attackLeft()
        on.arrowKey(key) -- actually this might not work
    end
end
  • Calculators owned: Casio CFX-9850, TI-Nspire
  • Consoles, mobile devices and vintage computers owned: HTC One, Huawei Honor 10
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC TI-nspire Hold 'em Health Bar Scissors Paper Rock
TI-nspire Lua Numstrat TI-nspire Hold 'em Lua Transport Chooser Secret Project (at v0.08.2 - 2015/05/08)

Strontium

You'd have to call on.charIn(char) for that. But besides that, on.arrowKey is something that is called whenever you press the arrow keys on the Nspire. Furthermore, since this still using on.charIn pretty much the same way as before, I don't think it will work.
  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES

Jonius7

Perhaps pass the last arrow key you pressed to another variable, and then check the value of that variable when you press "6", so you can continue the moving code accordingly.
  • Calculators owned: Casio CFX-9850, TI-Nspire
  • Consoles, mobile devices and vintage computers owned: HTC One, Huawei Honor 10
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC TI-nspire Hold 'em Health Bar Scissors Paper Rock
TI-nspire Lua Numstrat TI-nspire Hold 'em Lua Transport Chooser Secret Project (at v0.08.2 - 2015/05/08)

Powered by EzPortal