The nice part is here:
end end end end end end
Maybe something like
self.letter[n]
The nice part is here:
end end end end end end
Maybe something like
self.letter[n]
@mentioned {Will mention everyone}
How to create objects? I already have the class and all the data, but how to create new objects?
@TokOut I’m starting to wonder if you even read the ebooks everyone constantly links you to. They’re very clear, and answer a lot of the simple questions you keep posting here.
Once more: the ebook ‘Lua for beginners’ by Ignatz, chapter 11, tells you all the basic stuff about classes you need to know. It can be found in the wiki or here:
https://www.dropbox.com/sh/mr2yzp07vffskxt/AABlplSGGFBTu8FzQy94lteua/Lua%20for%20beginners.pdf
I haven’t dropbox
you don’t need dropbox.
you can ignore the login message
Though Dropbox is by far the easiest way of managing your Codea assets IMO, so should be something every Codea user has.
@TokOut - of course, you would know, being such a Codea expert
Keyboard class: < Codea Ralk is better! >
KeyBoard = class()
function KeyBoard:init()
-- You can accept and set parameyers here
-- To make the key visible if you have in setup "k = KeyBoard()" then use "k.visible = true"
self.visible = false
self.textSize = 25
self.xy = 68
self.letters = {"1","z","a","q","2","x","s","w","3","c","d","e","4","v","f","r","5","b","g","t","6","n","h","y","7","m","j","u","8", ",","k","i","9",".","l", "o", "0", "!","?","p","_",'"',"(","BCK",";","/",")","RET"}
self.positions = {}
end
function KeyBoard:draw()
local n = 0
if self.visible then
for x = 1, 12 do
self.positions[x] = {}
for y = 1, 4 do
n = n + 1
fill(255, 255, 255, 255)
rect(x * self.xy + self.xy/2, y * self.xy + self.xy/2, self.xy, self.xy)
fill(0, 0, 0, 255)
if self.bolden then font("Arial-BoldMT") else font("ArialMT") end
fontSize(self.textSize)
text(self.letters[n], x * self.xy + self.xy, y * self.xy + self.xy)
end
end
end
end
function KeyBoard:touched(t)
if self.visible then
local n = 0
for x = 1, 12 do
self.positions[x] = {}
for y = 1, 4 do
n = n + 1
local y = y
if t.x>self.xy*x+self.xy/2 and t.x<self.xy*x+self.xy*1.5 and t.y>self.xy*y+self.xy/2 and t.y<self.xy*y+self.xy*1.5 and t.state == BEGAN then
print(self.letters[n])
end
end
end
end
end
Shouldn’t the BCK key delete the previous letter?
And shouldn’t the class return the whole string?
That’s just an example! How to use it will be from you. This could be also used as calculator buttons. But that’s just an example, which means only the start code