Author Topic: Lua Q&A  (Read 104095 times)

0 Members and 1 Guest are viewing this topic.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Lua Q&A
« Reply #120 on: November 06, 2011, 03:27:14 pm »
You cal also do that, if you want the text to appear/disappear when pressing enter multiple times :

Code: [Select]
enterHasBeenPressed = false --initializes enterHasBeenPressed to be false
function on.paint(gc)
if enterHasBeenPressed then --execute the following code if enterHasBeenPressed is true
gc:drawString("Hello World", 0, 0, "top")
end
end
function on.enterKey()
enterHasBeenPressed = not enterHasBeenPressed -- will become true if false and false if true (switch state)
platform.window:invalidate()         --invalidates the window (basically, on.paint will be called)
end
« Last Edit: January 07, 2012, 05:47:09 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Lakuuni

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #121 on: November 07, 2011, 11:27:27 am »
Great thanks to all of you, Levak, 3rik and Adriweb. I don't know what I would do without you guys helping me take my first steps. You've been really helpful.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Lua Q&A
« Reply #122 on: November 07, 2011, 12:29:35 pm »
No problem :)
« Last Edit: November 07, 2011, 01:24:05 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline renatose

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 209
  • Rating: +4/-0
  • watch out the power balls
    • View Profile
Re: Lua Q&A
« Reply #123 on: November 27, 2011, 06:52:23 pm »
Is there any lua function to call nspire's BASIC commands?

It would ease my life a lot if I could use Text and Request commands...

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #124 on: November 28, 2011, 12:18:44 am »
As far as I'm aware, commands that are usable by functions can be accessed using math.eval() but commands like Request and Text are only available in programs.

Visit http://ourl.ca/12647 for more information.

An example of the usage of math.eval is located here: http://www.inspired-lua.org/2011/08/save-a-high-score-without-cheating-possibility/

Quote from: Nspire Scripting Application Programming Interface
Code: [Select]
math.eval(math_expression)This function sends an expression or command to the Nspire math server for evaluation. The input expression must be a string that the Nspire math server can interpret and evaluate.
If the math server successfully evaluates the expression, it returns the numerical results. The eval function returns no result if the math server does not return a calculated result or if the calculated result cannot be represented as a fundamental Lua data type.
If the math server cannot evaluate the expression because of a syntax, simplification, or semantic error, eval returns two results: nil and an error number.
Userbars

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Q&A
« Reply #125 on: November 28, 2011, 03:04:39 am »
Indeed, math.eval() allows you to run quite some basic functions, but Request and Text are not available.
It isn't too hard to program it though, once you get the hang of Lua on the nspire.
The best way would be to implant a Screen Manager (hint, Levak's sudoku), that easily allows you to have different 'screens'.
Then just make a screen for a popup, and you are done :)

Offline renatose

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 209
  • Rating: +4/-0
  • watch out the power balls
    • View Profile
Re: Lua Q&A
« Reply #126 on: November 28, 2011, 05:07:06 pm »
Ok, thank you 3rik and jimbauwens. So what you're telling me is that I can call virtually any basic function except the commands I want to... Right?

I'll take a look at Levak's Sudoku then we'll see if I can do it.

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Lua Q&A
« Reply #127 on: January 06, 2012, 07:14:57 pm »
Not a very active topic, it seems :P

Ok, I want to draw a game board. I tried using fillRect, filArc and such but I'm a total failure at it.

Nick says not to use ti-image because it will be really slow...

Is there any other way?

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #128 on: January 06, 2012, 11:18:22 pm »
If you have the choice between fillRect, fillArc, or fillPolygon and drawImage, I'd go with the fill functions. Obviously if you want some intricate pattern on the screen it is ridiculous to put hundreds of fillRects but if it is something relatively simple then it is usually a good choice. Personally I've only noticed a speed difference when there's a lot of images being drawn, however, images take up a bunch of memory compared to fillRect.

If you want to just draw a simple chess board you could do something like this:

Code: [Select]
function on.paint(gc)
gc:setColorRGB(0, 0, 0)
draw = false
for column=1, 8 do
draw = not draw
for row=1, 8 do
draw = not draw
if draw then
gc:fillRect(column * 25 - 19, row * 25 - 19, 25, 25)
end
end
end
gc:drawRect(5, 5, 201, 201)
end

I'm not sure if I answered your question but I hope this helps.
Userbars

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Lua Q&A
« Reply #129 on: January 06, 2012, 11:19:10 pm »
I got it already using a bunch of shapes, but thanks anyways :)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Lua Q&A
« Reply #130 on: June 13, 2012, 10:42:50 am »
Can LÖVE be used on the Nspire?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Q&A
« Reply #131 on: June 13, 2012, 10:48:58 am »
The syntax is very similar, it will be not too hard to port programs. But Love has certain functions that can not be created easily in the Nspire API.
It would be possible how to create a runner that runs simple love games (in pure lua).

Edit: it would be definitely possible if you get some help of extLua :P
« Last Edit: June 13, 2012, 10:49:30 am by jimbauwens »

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Lua Q&A
« Reply #132 on: September 22, 2012, 11:28:53 pm »
This may have been mentioned before, but is it possible to do anything similar to Request and RequestStr in TI-nspire Basic on Lua?
I want the user to be able to input a few numbers, and see what number they are typing I guess.

If not I can work around with pressing "up" and "down" buttons to change these numbers in the program, but I'll just have to change the programming around a bit.
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
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)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Lua Q&A
« Reply #133 on: September 23, 2012, 05:06:00 pm »
Yeah, it's kinda annoying not to have one. There was an article on Inspired Lua about it: http://www.inspired-lua.org/2011/12/how-to-have-a-nice-little-input-function-in-lua/

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Lua Q&A
« Reply #134 on: September 24, 2012, 02:19:54 am »
Ok I have an idea to just capture certain characters the user types and display them separately but concatenated as a single string.
EDIT: Oh yes that's what I was looking for thanks cyano.
« Last Edit: September 24, 2012, 02:20:24 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
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)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)