- 123outerme's Nspire Lua Questions
- 22 Jan 2017 10:49:32 am
- Last edited by 123outerme on 24 Jan 2017 07:43:20 pm; edited 1 time in total
If I haven't hammered it in to everyone's skulls in SAX yet, I'm getting a TI-nspire Clickpad (yes, with the 84+ keyboard). I'm probably gonna be starting out in Lua, and transitioning to C once I get the hang of it all. In the meantime, I have some questions regarding Lua, specifically on the Nspire:
1. Can I import different libaries on the Nspire? If so, what would be the syntax for importing it? I know how to run a library function (obviously, just like any other), but how would I load the library?
Answer: Never mind, I did some digging in https://wiki.inspired-lua.org/ and I found it.
2. How would you get input from the keypad? Is there a list of keycodes?
Answer: Not specifically, no, but there's a way to get keypresses for letters and stuff (basically give a variable specifically for reading keypresses, and... you know what, just read it, I give up Here
3. I read somewhere that as of the latest OSes, print("blah") outputs to a console, not to the screen. Is this true?
Answer: Yes. Most useful using Jens' Script Editor.
4. How would I go about making a program detect differences in calculator models, such that I don't try to display color to a monochrome screen, but I can still display color to a color screen, without asking the user?
Answer: Never mind, I found this too, at the Nspire Lua Wiki also.
5. Can someone explain to me how events work? I'm not entirely understanding it. I get that it handles when you do something, but why is it in a function definition every time I see it, yet it isn't apparently being defined as a function at all?
Answer: Events, upon being "triggered" (on.paint is called by platform.window:invalidate, key input like on.enterKey is called just by pressing Enter, etc.), run the code inside the "function definition".
6. Is there a way I can draw something to the screen again using a custom function like so:
Code:
and not have it wipe the screen?
Answer: Yes, like so:
Code:
1. Can I import different libaries on the Nspire? If so, what would be the syntax for importing it? I know how to run a library function (obviously, just like any other), but how would I load the library?
Answer: Never mind, I did some digging in https://wiki.inspired-lua.org/ and I found it.
2. How would you get input from the keypad? Is there a list of keycodes?
Answer: Not specifically, no, but there's a way to get keypresses for letters and stuff (basically give a variable specifically for reading keypresses, and... you know what, just read it, I give up Here
3. I read somewhere that as of the latest OSes, print("blah") outputs to a console, not to the screen. Is this true?
Answer: Yes. Most useful using Jens' Script Editor.
4. How would I go about making a program detect differences in calculator models, such that I don't try to display color to a monochrome screen, but I can still display color to a color screen, without asking the user?
Answer: Never mind, I found this too, at the Nspire Lua Wiki also.
5. Can someone explain to me how events work? I'm not entirely understanding it. I get that it handles when you do something, but why is it in a function definition every time I see it, yet it isn't apparently being defined as a function at all?
Answer: Events, upon being "triggered" (on.paint is called by platform.window:invalidate, key input like on.enterKey is called just by pressing Enter, etc.), run the code inside the "function definition".
6. Is there a way I can draw something to the screen again using a custom function like so:
Code:
function digits (a)
return 1 + math.floor(math.log10(a))
end
function textDisp(string, x, y) //-- This custom function here
function on.paint(gc)
gc:drawString(string, x, y)
end
return string
end
textDisp("hello world!", 320, 240)
textDisp(digits(100), 0, 20)
and not have it wipe the screen?
Answer: Yes, like so:
Code:
function on.paint(gc)
function textDisp(string, x, y)
gc:drawString(string, x, y)
end
textDisp("hello world!", 320, 240)
textDisp(digits(100), 0, 20)
end
platform.window:invalidate() //-- Calls the code in "function on.paint(gc)". The function definition for any custom function you use doesn't have to be inside the "function on.paint(gc)" definition.