Author Topic: Getting started with Lua on Nspire  (Read 10199 times)

0 Members and 1 Guest are viewing this topic.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Getting started with Lua on Nspire
« on: December 29, 2011, 11:57:49 pm »
Okay, I would like to learn how to code Lua on an nspire!
My OS is 3.1.0.392
I would really like to learn how to make menu's...
Also making pictures... and many moar things in Lua!
Please help!
Thanks!
« Last Edit: December 30, 2011, 12:29:31 am by hellninjas »

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Nspire Basic
« Reply #1 on: December 30, 2011, 12:07:18 am »
No menus on the nspire
XXX->Varname (up to 16 chars IIRC) and that can be literally anything from matrices to strings to ints to floats
no way to display pics directly. Plotting points can be a method that takes forever. Also, there's no output command.

The best way I've found to do any sort of proper display method was the text box, or regular disp with matrices.

You should also become VERY familiar with the string commands:

Left()
Mid()
right()
str & str
instring()

See the nspire catalog for a syntax example. Left takes a number of chars starting from the left of a string and returns that substring. same goes for right. Mid is identical to the 84+ sub(). & is the equivalent of str+str in 84+ basic. Instring finds the position of one string inside of another, and returns a particular int (0 I think) if it doesn't find any. It gives the first one then stops, so multiples are undetected.

request and requeststr are the only ways of getting in-prog input, but there are also inline args when you run the program. ex. prog(a,b,c) where a b and c are vars of any type that become vars in your program.

Local var is a great way of avoiding variable collisions between progs, it makes it so a var doesn't affect a var by the same name outside the program. Example:

Out of program:
6->a

in program:
local a
"hello"->a
end program:

disp a
 - Returns 6

No way to exit PTT from basic :P that's one of the many uses for ndless. besides, you can't run basic progs from within PTT anyways, unless you make them on the spot.

I probably got one or two things wrong, but that's about as far as BASIC can go while remaining inside one program. If you're not afraid of using multiple programs
« Last Edit: December 30, 2011, 12:09:36 am by willrandship »

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Nspire Basic
« Reply #2 on: December 30, 2011, 12:12:37 am »
No menu's eh?
Ndless it is...
Is there an Ndless for OS 3.1.0.392?

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Nspire Basic
« Reply #3 on: December 30, 2011, 12:14:55 am »
not yet ;) but there's already a closed beta, so it can't be very far off.

Have you considered Lua? It's much better, being a real language and all. Not to mention faster. AND it can be programmed on-calc if you send the right progs.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Nspire Basic
« Reply #4 on: December 30, 2011, 12:17:03 am »
How would I do this? It sounds like a nice idea :D
Nice Prof Pic btw... xD

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Nspire Basic
« Reply #5 on: December 30, 2011, 12:21:35 am »
hehe yeah...:P

TI was nice and gave us Lua to use on OSes above 2.1. I don't know much about it, but there's a ton of people on this forum who do (I stuck to 2.1 so I could keep ndless, but with ndless 3 I'll switch)

Also, you actually posted in the Lua subforum :P Change the title to "Getting started with Lua" or something similar and you'll be all set.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #6 on: December 30, 2011, 12:31:18 am »
Done!
Thankx for teh reccomendation!
I can't wait for Lua! :D

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #7 on: December 30, 2011, 12:55:18 am »
to make pictures, you can use all of the drawing commands, or you can convert a pic to a ti.image although this is realy large and re-drawing the screen will slow down
to make a menu...if you ever read the tibasicdev article on making custom menus thats basicly what you would have to do it in lua, as there isnt a
"Menu(" command
Lua is realy easy to learn everything is event/function based
Lua example:
Code: [Select]
function on.paint(gc)
    gc:setColorRGB(0, 0, 0)--set the color to black
    gc:drawRect(3, 3, 50, 50)--draws a rectangle on the screen with black lines
    gc:fillRect(100, 0, 50, 50)--makes a rectangle that is filled with the color black
end
to find some tutorials go to: http://www.inspired-lua.org/
to get the official scripting tools go to: http://education.ti.com/educationportal/sites/US/nonProductSingle/nspire-scripting.html
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #8 on: December 30, 2011, 12:57:17 am »
I can't wait for Lua! :D
Why wait? :P

Also, can you make sprites in lua?
« Last Edit: December 30, 2011, 01:00:22 am by epic7 »

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #9 on: December 30, 2011, 01:15:33 am »
you could make sprites, i would suggest using classes, but you would have to use one of the two methods i talked about above for drawing them
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Getting started with Lua on Nspire
« Reply #10 on: December 30, 2011, 04:15:30 am »
There is TI.Image, no need to create your own routine for that.
You just need img=image.new(data) to create the sprite, and gc:drawImage(img,x,y) to draw it.

Edit, misunderstood your previous post. TI.Image isn't to slow if you use it wisely ;)
« Last Edit: December 30, 2011, 04:17:00 am by jimbauwens »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Getting started with Lua on Nspire
« Reply #11 on: December 30, 2011, 04:38:53 am »
and it will be even faster soon ;)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #12 on: December 30, 2011, 10:52:07 am »
well thats good to know that it will be faster and i wasnt that clear either, i should have put in my post the larger they are- the more that everything lags when its redrawing
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #13 on: December 30, 2011, 02:06:54 pm »
I see alot of people coding on the computer and transfering to the calc, but how would I program ON-Calc ?

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Getting started with Lua on Nspire
« Reply #14 on: December 30, 2011, 03:40:55 pm »
You can use the default notes application and then copy and paste to oclua or you can use LuaCS and copy to paste to Oclua.

For on-calc sprites, you can use Chockosta's nSpaint.

You can't really get .tns oncalc, at least I don't think so...
« Last Edit: December 30, 2011, 03:41:49 pm by cyanophycean314 »