* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: TI Nspire Lua things  (Read 1243 times)

0 Members and 1 Guest are viewing this topic.

Offline Strontium

  • Full User
  • Join Date: Apr 2015
  • Location: CA
  • Posts: 236
  • Post Rating Ratio: +3/-2
  • hey
    • Unilunge
    • /u/thismarkstheend
    • Azmarok
  • Gender: Other
TI Nspire Lua things
« on: April 22, 2015, 11:06:39 pm »
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:
Code: [Select]
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?
« Last Edit: April 22, 2015, 11:49:19 pm by Strontium »


  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES

Offline alexgt

  • Just your friendly neighborhood Ninja Stach Fancy Iron Man
  • Super User
  • Join Date: Dec 2014
  • Location: Behind you
  • Posts: 2611
  • Post Rating Ratio: +6/-1
  • Something should go here...
    • /u/alexgt9123
  • Gender: Male
Re: TI Nspire Lua things
« Reply #1 on: April 22, 2015, 11:14:55 pm »
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

Offline Jonius7

  • New User
  • Join Date: May 2015
  • Location:
  • Posts: 8
  • Post Rating Ratio: +0/-0
Re: TI Nspire Lua things
« Reply #2 on: May 07, 2015, 11:25:26 pm »
Perhaps this is worth a try:

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

Code: [Select]
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
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)

Offline Strontium

  • Full User
  • Join Date: Apr 2015
  • Location: CA
  • Posts: 236
  • Post Rating Ratio: +3/-2
  • hey
    • Unilunge
    • /u/thismarkstheend
    • Azmarok
  • Gender: Other
Re: TI Nspire Lua things
« Reply #3 on: May 07, 2015, 11:35:54 pm »
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

Offline Jonius7

  • New User
  • Join Date: May 2015
  • Location:
  • Posts: 8
  • Post Rating Ratio: +0/-0
Re: TI Nspire Lua things
« Reply #4 on: May 08, 2015, 12:15:37 am »
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.
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)

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games