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

0 Members and 2 Guests are viewing this topic.

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 #15 on: July 01, 2011, 04:03:20 pm »
There is a D2Editor, but it really is buggy, so you can't use it.

You can make something like this:
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

Of course you will have to do some changes to make it usable, but it should show the basics.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Lua Q&A
« Reply #16 on: July 02, 2011, 04:30:15 am »
Try to use the class D2Editor.

[edit] sorry I missed jimbauwens's post.

jimbauwens, what's wrong with it? The scrolling?
« Last Edit: July 02, 2011, 04:31:54 am by ExtendeD »
Ndless.me with the finest TI-Nspire programs

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #17 on: July 02, 2011, 10:35:14 am »
Try to use the class D2Editor.

[edit] sorry I missed jimbauwens's post.

jimbauwens, what's wrong with it? The scrolling?

Because we can't edit it on ClickPad ? (or even I'm stupid)
« Last Edit: July 02, 2011, 10:35:27 am 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 pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Lua Q&A
« Reply #18 on: July 02, 2011, 10:56:10 am »
Ok, thank you.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Lua Q&A
« Reply #19 on: July 02, 2011, 02:06:20 pm »
Levak: you mean you can't set the focus on it? A quick try with a single D2Editor on the screen gets the focus on nspire_emu.
Ndless.me with the finest TI-Nspire programs

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #20 on: July 02, 2011, 03:30:20 pm »
Levak: you mean you can't set the focus on it? A quick try with a single D2Editor on the screen gets the focus on nspire_emu.
I can't. setFocus is a nil value :

Code: [Select]
function on.create()
editor = D2Editor.newRichText()
editor:move(50,50)
editor:resize(200,100)
end
 
function on.charIn(char)
currentText = editor:getText()
editor:setText(currentText .. char) --Add char to the editor
end
 
function on.enterKey()
on.charIn(string.char(10)) --Add a new line
end

function on.tabKey()
if focus then
focus = false
D2Editor.setFocus(false)
else
focus = true
D2Editor.setFocus(false)
end
end

But yes, if I type some keys, it enters the text, OK.

I have thus found another reason to not use the D2Editor : we can't delete it.
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

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 #21 on: July 02, 2011, 03:54:43 pm »
The D2Editor also sucks events for some reason, and my programs start acting really weird after a while. I really would like to use it, but its so bugged that I can't. It just get to anoying after a time.

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Lua Q&A
« Reply #22 on: July 09, 2011, 07:14:18 pm »
Is there a way to resize images in the program?

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #23 on: July 09, 2011, 07:20:22 pm »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Lua Q&A
« Reply #24 on: July 09, 2011, 07:23:59 pm »
Thanks, Levak!

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #25 on: July 15, 2011, 09:16:46 am »
........... function on.paint(gc) .......Text=editor:getText()  gc:drawString(Text,0,0) end   May this work

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 #26 on: July 15, 2011, 01:26:39 pm »
cypressx1, You can put Lua code in [ code] tag's for better readability :)

Your code is correct, but you must make sure that you have an editor created (D2editor), and that you sometimes invalidate your screen. Also, you should add "top" to your drawString, because now it will be a bit ofscreen:
Code: (Lua) [Select]
gc:drawString(Text,0,0,"top")

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
Re: Lua Q&A
« Reply #27 on: July 18, 2011, 08:22:08 am »
Thanks!

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Lua Q&A
« Reply #28 on: July 24, 2011, 05:08:06 pm »
Has anybody achieved +- smoothscrolling?

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Lua Q&A
« Reply #29 on: July 24, 2011, 08:14:32 pm »
I know the Copter game had smooth scrolling but then again those graphics were simple.