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

0 Members and 2 Guests are viewing this topic.

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Lua Q&A
« Reply #105 on: October 05, 2011, 06:03:54 pm »
Hey, i could use that, Levak :D
* pianoman slaps himself with a netham for not thinking of that

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: Lua Q&A
« Reply #106 on: October 05, 2011, 07:40:37 pm »
I have a question about the tool palate. Am I able to use it to get two separate input fields on a single menu?

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua Q&A
« Reply #107 on: October 05, 2011, 08:20:32 pm »
How does grayscale work on the non CX calcs ? More importantly how do I use it ?
How many levels of grayscale does the normal NSpire support ?
How does this work with the TI-Image format ?

I'm asking since I'm writing a .BMP file -> TI-Image file convert for easy Lua usage.
Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Lua Q&A
« Reply #108 on: October 05, 2011, 11:32:52 pm »
How does grayscale work on the non CX calcs ? More importantly how do I use it ?
How many levels of grayscale does the normal NSpire support ?
How does this work with the TI-Image format ?

I'm asking since I'm writing a .BMP file -> TI-Image file convert for easy Lua usage.

TI-Image is always in 16-bit color format, and on the grayscale calculators it is converted automatically. Oh, and there are 15 shades of grayscale, since you wanted to know.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Lua Q&A
« Reply #109 on: October 05, 2011, 11:33:37 pm »
How does grayscale work on the non CX calcs ? More importantly how do I use it ?
How many levels of grayscale does the normal NSpire support ?
How does this work with the TI-Image format ?

I'm asking since I'm writing a .BMP file -> TI-Image file convert for easy Lua usage.
I think the official tool does that, but if you would like to as well, more power to you!

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 #110 on: October 06, 2011, 01:41:19 am »
TI-Image is always in 16-bit color format, and on the grayscale calculators it is converted automatically. Oh, and there are 15 shades of grayscale, since you wanted to know.
TI.Image is actually 15 bit color, and one alpha bit.

Check out the (outdated) info on Inspired Lua, and the official documentation, they should be clear enough.
You can also check out my python converter at http://bwns.be/jim/convert.py. It's pretty easy to understand :)

@homer, I don't understand your question fully, mind explaining a bit more? :D

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: Lua Q&A
« Reply #111 on: October 06, 2011, 12:00:44 pm »
Basically I want to know if I can use the tool palate to create a menu with an area where you can input a number or character.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

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 #112 on: October 06, 2011, 12:59:06 pm »
I don't think so, the tool palette is quite limited, so you will have to make your own.
I recommend you to check out Levak's Sudoku code, where he implemented a "screen manager". This will be of big help if you want to make your own menu system (and other stuff).

Offline Sebasu

  • LV2 Member (Next: 40)
  • **
  • Posts: 31
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #113 on: October 26, 2011, 05:37:54 pm »
Hello, i wanta to make an screen with areas to input numbers, i have checked the levak's sudoku code but i can´t understand completely, can somebody make me an example?
it would be a big help

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 #114 on: October 27, 2011, 03:03:22 am »
Do you mean like a textbox?

Code: (Lua) [Select]
msg = ""

function on.paint(gc)
  gc:drawString(msg, 10, 10, "top")
end

function on.charIn(ch)
  msg = msg .. ch
  platform.window:invalidate()
end

What happens here is that on.charIn get called everytime you press a character key. We then add the character to the variable msg and invalidate the screen.
Because we invalidated the screen, on.paint() gets called and displays the string on the screen :)

Offline Sebasu

  • LV2 Member (Next: 40)
  • **
  • Posts: 31
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #115 on: October 30, 2011, 06:13:10 pm »
wow amazing
simpler than I thought
thanks jimbauwens

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 #116 on: October 30, 2011, 06:14:11 pm »
Glad I could be a help :)

Offline Lakuuni

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #117 on: November 06, 2011, 12:13:50 pm »
I'm quite new to lua and I've just started to do my own simple experiments with it to get the gist of the language and programming for calculator. Now I'm trying to figure out how to get input from the user via nspire's keyboard. To do that I've tried exploring lua.org, hackspire wiki, google and lua programs posted on this forum, but when trying to create a simple program that would for example print "hello world" when the user presses the enter key, it seems to notice the enter being pressed only when pressing it after for example catalog button. This obviously isn't very useful when planning real projects so I ask you to guide me to a batter way of achieving communications between program and it's user.
Here's the code I tried:
Code: [Select]
function on.enterKey()
function on.paint(gc)
gc:drawString("Hello World!",0,0,"top")
end
end

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #118 on: November 06, 2011, 12:23:33 pm »
This will work, but it is really dirty :P
You forgot to use platform.window:invalidate() that indicates the Nspire framework you want to refresh teh screen (note that on.paint is not called as soon as you call platform.window:invalidate() )

This will work :

Code: [Select]
function on.paint(gc)
if hello then
gc:drawString("Hello World!", 0, 0, "top")
end
end

function on.enterKey()
hello = true
platform.window:invalidate()
end

Have you looked at http://inspired-lua.org ?
« Last Edit: November 06, 2011, 12:24:23 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #119 on: November 06, 2011, 12:37:35 pm »
When you start an Nspire Lua program, the calculator goes through the program and initializes any functions or variables and runs any instructions outside a function. Then it continues to loop through the event functions. In your example, when the program starts, on.enterKey() is initialized. When the enter key is pressed, the on.enterKey function is called. The on.paint function is defined here instead of having it be defined at the beginning. But the on.paint function is only called by the calculator when the window is "invalidated." The window starts out invalidated but becomes valid after the on.pain function is called. Moving the cursor or opening the catalog invalidates the screen and this is why your function works the way it does. To purposely invalidate the window (thus calling on.paint at the end of the current function) you can use the platform.window:invalidate() function. To summarize all this, here is code that accomplishes what you were trying to do.

Code: [Select]
enterHasBeenPressed = false --initializes enterHasBeenPressed to be false
function on.paint(gc)
if enterHasBeenPressed then --exicute the following code if enterHasBeenPressed is true
gc:drawString("Hello World", 0, 0, "top")
end
end
function on.enterKey()
enterHasBeenPressed = true --Since enter has been pressed enterHasBeenPressed is now true
platform.window:invalidate()        --invalidates the window so when on.enter is done on.paint will be called
end
Having events being called takes a bit to get used to if you're used to a purely sequental language, but if you keep trying, you'll catch on. ;)
Also if you haven't already, introduce yourself here.
Welcome to Omnimaga! :D


Edit: Ninja'd

I suppose enterHasBeenPressed doesn't actually need to be set to false at the beginning but explicitly telling it to be false is good for other humans reading it. Both ways work.

Also remember that just because you've initialized a function, it doesn't mean it will be called. The special event functions (like on.paint) are tricky because in simple programs this seems to be the case.
« Last Edit: November 06, 2011, 01:19:03 pm by 3rik »
Userbars