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 Razz 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.
3: Correct, print("blah") will print to an invisible console (or a visible one if you're using JensScriptEditor)

5: Events are just functions that you make with a specific name, so the OS will call them when the appropriate events happen.

6: Not wiping the screen isn't really the way you want to do things (nor can you really). The Nspire is fast enough that you redraw the entire screen every frame.
Ivoah wrote:
3: Correct, print("blah") will print to an invisible console (or a visible one if you're using JensScriptEditor)

5: Events are just functions that you make with a specific name, so the OS will call them when the appropriate events happen.

6: Not wiping the screen isn't really the way you want to do things (nor can you really). The Nspire is fast enough that you redraw the entire screen every frame.

3. Okay, got it.
5. So when I call on.paint, I'm basically calling a screen clear, then calling the remaining code?
6. Is there a way to do what my code was trying to do (assuming on.paint didn't wipe the screen)? AKA how would I write a function to draw to the screen and keep the stuff there before it, so I can call that function iteratively?
And a specific question about the graphics context: How would I update the gc without wiping the screen?
123outerme wrote:
Ivoah wrote:
3: Correct, print("blah") will print to an invisible console (or a visible one if you're using JensScriptEditor)

5: Events are just functions that you make with a specific name, so the OS will call them when the appropriate events happen.

6: Not wiping the screen isn't really the way you want to do things (nor can you really). The Nspire is fast enough that you redraw the entire screen every frame.

3. Okay, got it.
5. So when I call on.paint, I'm basically calling a screen clear, then calling the remaining code?
6. Is there a way to do what my code was trying to do (assuming on.paint didn't wipe the screen)? AKA how would I write a function to draw to the screen and keep the stuff there before it, so I can call that function iteratively?
And a specific question about the graphics context: How would I update the gc without wiping the screen?


5: You don't call on.paint. You call platform.window:invalidate(), which will erase the screen and then call your on.paint function. I usually set up a timer to call it every 1/60 of a second, like this:

Code:

timer.start(1/60)
function on.timer()
    platform.window:invalidate()
end


Now on.paint will be called 60 times a second.

As for the other questions, I don't think it's possible to update the screen without erasing everything first.
Ivoah wrote:
I don't think it's possible to update the screen without erasing everything first.

Well, partial screen invalidation (look at the optional params) is a thing, and is very much encouraged if you can, since it'll be faster to [re]draw stuff.
Ivoah wrote:
123outerme wrote:
Ivoah wrote:
3: Correct, print("blah") will print to an invisible console (or a visible one if you're using JensScriptEditor)

5: Events are just functions that you make with a specific name, so the OS will call them when the appropriate events happen.

6: Not wiping the screen isn't really the way you want to do things (nor can you really). The Nspire is fast enough that you redraw the entire screen every frame.

3. Okay, got it.
5. So when I call on.paint, I'm basically calling a screen clear, then calling the remaining code?
6. Is there a way to do what my code was trying to do (assuming on.paint didn't wipe the screen)? AKA how would I write a function to draw to the screen and keep the stuff there before it, so I can call that function iteratively?
And a specific question about the graphics context: How would I update the gc without wiping the screen?


5: You don't call on.paint. You call platform.window:invalidate(), which will erase the screen and then call your on.paint function. I usually set up a timer to call it every 1/60 of a second, like this:

Code:

timer.start(1/60)
function on.timer()
    platform.window:invalidate()
end


Now on.paint will be called 60 times a second.

As for the other questions, I don't think it's possible to update the screen without erasing everything first.

Okay, thanks! I'll be sure to use platform.window:invalidate() then.
Adriweb wrote:
Ivoah wrote:
I don't think it's possible to update the screen without erasing everything first.

Well, partial screen invalidation (look at the optional params) is a thing, and is very much encouraged if you can, since it'll be faster to [re]draw stuff.

So if I set the parameters to where I'm not drawing, I can keep drawing to the screen and not destroying the stuff I've written already? Also, will it throw an error if I set the window for it to erase outside of displayable range? Or, if the window to redraw is 0 pixels in any dimension?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement