Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Another Text Input field

edited November 2014 in Code Sharing Posts: 57

Hi. I've noticed that questions about how to add Text Input fields are posted quite frequently in the forums, but I have never found a complete solution that allows to place the cursor at an arbitrary position to insert text or if it does then it lacks backspace and return support, etc. I started coding one to cater for my specific needs, but I realised it's more complex than what I thought when started. Anyway, I have a solution that solves my problem but I think it is a quite large piece of code to do what can be done in HTML with just 1 line. I appreciate suggestions to make this code shorter or, ideally, use a 1-liner solution for text input.

Demo here:

The Main class shows how to use it, and the actual Input text field code is shown after this

-- Main class

function setup()
    local x = 30
    local w = 300
    local h = 25

    local obj = InputTarget() -- Sample handler

    input1 = Input(x, HEIGHT-100, w, h, "CourierNewPSMT", "ABCDEFGHIJKLMNOPQRSTUVWXYZ") 
    input2 = Input(x, HEIGHT-160, w, h, "AppleColorEmoji", "A string exceeding the visible size of the field")
    input3 = Input(x, HEIGHT-220, w, h, "GillSans-Light", "global handler", globalHandler)
    input4 = Input(x, HEIGHT-280, w, h, "HelveticaNeue", "instance handler 1", obj.hand1, obj)
    input5 = Input(x, HEIGHT-340, w, h, "Verdana", "instance handler 2", obj.hand2, obj)
end

function draw()
    background(228, 228, 224, 255)
    strokeWidth(5)
    Input._draw()
end

-- Example of a global handler function

function globalHandler(txt)
    print("Global -> "..txt)
end

-- Example of an input handler class

InputTarget = class()

function InputTarget:hand1(txt)
    print("obj:hand1 -> "..txt)
end

function InputTarget:hand2(txt)
    print("obj:hand2 -> "..txt)
end

This is the actual Text Input code


--[[-- GLOBAL FUNCTIONS These global functions can be declared out of this file if required --]]-- function keyboard(key) Input._put(key) end function touched(touch) Input._touched(touch) end --[[ INPUT CLASS ]]-- Input = class() Input.instances = {} local padding = 10 --[[ Class functions ]]-- function Input._draw() for _,input in ipairs(Input.instances) do input:draw() end end function Input._touched(touch) for _,input in ipairs(Input.instances) do input:touched(touch) end end function Input._put(key) for _,input in ipairs(Input.instances) do if input.focus then input:put(key) end end end --[[ Instance functions ]]-- function Input:init(x, y, w, h, fontName, txt, onEnter, target) table.insert(Input.instances, self) self.fontSize = h self.fontName = fontName font(self.fontName) fontSize(self.fontSize) self.x = x self.y = y self.w = w self.h = h if txt then self.txt = txt else self.txt = "" end self.pos = string.len(self.txt) self.winPos = 0 self.cursor = Cursor(self.h+padding/2) self:blur() if onEnter == nil then self.onEnter = function() print(self.txt) end else self.onEnter = onEnter end self.target = target end function Input:put(key) if key == BACKSPACE then self:backspace() elseif key == RETURN then self:enter() else self:insert(key) end end function Input:backspace() if self.pos > 0 then local head,tail = self:splitAndDrop(1) self.txt = head..tail self.pos = self.pos - 1 if self.pos == self.winPos and self.winPos > 0 then self.winPos = self.winPos - 1 end end end function Input:insert(key) local head,tail = self:splitAndDrop(0) self.txt = head..key..tail self.pos = self.pos + 1 while self.pos > self:winSize() do self.winPos = self.winPos + 1 end end function Input:enter() self:blur() if self.target then self.onEnter(self.target, self.txt) else self.onEnter(self.txt) end end function Input:splitAndDrop(dropCount) local head = string.sub(self.txt, 0, self.pos - dropCount) local tail = string.sub(self.txt, self.pos + 1) return head,tail end function Input:blur() self.focus = false hideKeyboard() end function Input:visiblePart() local winSize = self:winSize() return string.sub(self.txt, self.winPos + 1, self.winPos + winSize) end function Input:winSize() font(self.fontName) local winSize = string.len(self.txt) local part = string.sub(self.txt, self.winPos, self.winPos + winSize) local w,_ = textSize(part) while w > self.w do winSize = winSize - 1 part = string.sub(self.txt, self.winPos, self.winPos + winSize) w,_ = textSize(part) end return winSize end function Input:draw() pushMatrix() translate(self.x, self.y) pushStyle() self:showBox() self:showText() self:posCursor() if self.focus then self:showBorder() self.cursor:draw() end popStyle() popMatrix() end function Input:showBox() fill(255, 255, 255, 255) stroke(255, 255, 255, 255) strokeWidth(padding) rect(-padding, -padding, self.w+2*padding, self.h+2*padding) end function Input:showBorder() noFill() strokeWidth(2) stroke(127, 127, 127, 255) rect(-padding, -padding, self.w+2*padding, self.h+2*padding) end function Input:showText() font(self.fontName) textMode(CORNER) fill(0, 0, 0, 255) text(self:visiblePart(), 0, 0) end function Input:touched(touch) if self:contains(touch) then self.focus = true if not isKeyboardShowing() then showKeyboard() end if touch.state ~= ENDED then self:moveCursor(touch.x) end else self.focus = false end end function Input:contains(touch) return self.x <= touch.x and touch.x <= (self.x + self.w) and self.y <= touch.y and touch.y <= (self.y + self.h) end function Input:moveCursor(x) pushStyle() font(self.fontName) local min = math.huge local part = self:visiblePart() for i = 0,string.len(part) do local sub = string.sub(part, 0, i) local w,_ = textSize(sub) local dist = math.abs(x - (self.x + w)) if dist < min then min = dist self.pos = self.winPos + i end end popStyle() local rightEnd = self.winPos + self:winSize() if self.pos == self.winPos and self.winPos > 0 then self.winPos = self.winPos - 1 elseif self.pos == rightEnd and rightEnd < string.len(self.txt) then self.winPos = self.winPos + 1 end self:posCursor() end function Input:posCursor() pushStyle() font(self.fontName) local part = self:visiblePart() local relPos = self.pos - self.winPos local sub = string.sub(part, 0, relPos) self.cursor.x,_ = textSize(sub) popStyle() end Cursor = class() function Cursor:init(h) self.h = h self.x = 0 self.show = true tween.delay(0.4, Cursor._blink, self) end function Cursor:draw() if self.show then pushStyle() strokeWidth(3) stroke(0, 0, 0, 255) line(self.x, 0, self.x, self.h) popStyle() end end function Cursor._blink(cursor) cursor.show = not cursor.show tween.delay(0.4, Cursor._blink, cursor) end
Tagged:

Comments

  • Jmv38Jmv38 Mod
    edited August 2014 Posts: 3,295

    @lightDye this looks great!
    Would you mind removing the fancy coloring from your code post? I cant copy it from ipad1 with this option. Just use the stadard 3 ~ syntax. Thanks in advance.

    -- Main class
    
    function setup()
        local x = 30
        local w = 300
        local h = 25
    
        local obj = InputTarget() -- Sample handler
    
        input1 = Input(x, HEIGHT-100, w, h, "CourierNewPSMT", "ABCDEFGHIJKLMNOPQRSTUVWXYZ") 
        input2 = Input(x, HEIGHT-160, w, h, "AppleColorEmoji", "A string exceeding the visible size of the field")
        input3 = Input(x, HEIGHT-220, w, h, "GillSans-Light", "global handler", globalHandler)
        input4 = Input(x, HEIGHT-280, w, h, "HelveticaNeue", "instance handler 1", obj.hand1, obj)
        input5 = Input(x, HEIGHT-340, w, h, "Verdana", "instance handler 2", obj.hand2, obj)
    end
    
    function draw()
        background(228, 228, 224, 255)
        strokeWidth(5)
        Input._draw()
    end
    
    -- Example of a global handler function
    
    function globalHandler(txt)
        print("Global -> "..txt)
    end
    
    -- Example of an input handler class
    
    InputTarget = class()
    
    function InputTarget:hand1(txt)
        print("obj:hand1 -> "..txt)
    end
    
    function InputTarget:hand2(txt)
        print("obj:hand2 -> "..txt)
    end
    
    
    --[[--
    GLOBAL FUNCTIONS 
    These global functions can be declared out of this file if required
    --]]--
    
    
    function keyboard(key)
        Input._put(key)
    end
    
    function touched(touch)
        Input._touched(touch)
    end
    
    --[[ INPUT CLASS ]]--
    
    Input = class()
    
    Input.instances = {}
    
    local padding = 10
    
    --[[ Class functions ]]--
    
    function Input._draw()
        for _,input in ipairs(Input.instances) do
            input:draw()
        end
    end
    
    function Input._touched(touch)
        for _,input in ipairs(Input.instances) do
            input:touched(touch)
        end
    end
    
    function Input._put(key)
        for _,input in ipairs(Input.instances) do
            if input.focus then
                input:put(key)
            end
        end
    end
    
    --[[ Instance functions ]]--
    
    function Input:init(x, y, w, h, fontName, txt, onEnter, target)
        table.insert(Input.instances, self)
        self.fontSize = h
        self.fontName = fontName
        font(self.fontName)
        fontSize(self.fontSize)
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        if txt then
            self.txt = txt
        else
            self.txt = ""
        end
        self.pos = string.len(self.txt)
        self.winPos = 0
    
        self.cursor = Cursor(self.h+padding/2)
    
        self:blur()
        if onEnter == nil then
            self.onEnter = function() print(self.txt) end
        else
            self.onEnter = onEnter
        end
        self.target = target
    end
    
    function Input:put(key)
        if key == BACKSPACE then
            self:backspace()
        elseif key == RETURN then
            self:enter()
        else
            self:insert(key)        
        end
    end
    
    function Input:backspace()
        if self.pos > 0 then
            local head,tail = self:splitAndDrop(1)
            self.txt = head..tail
            self.pos = self.pos - 1
            if self.pos == self.winPos and self.winPos > 0 then
                self.winPos = self.winPos - 1
            end
        end
    end
    
    function Input:insert(key)
        local head,tail = self:splitAndDrop(0)
        self.txt = head..key..tail
        self.pos = self.pos + 1
        while self.pos > self:winSize() do
            self.winPos = self.winPos + 1
        end
    end
    
    function Input:enter()
        self:blur()
        if self.target then
            self.onEnter(self.target, self.txt)
        else
            self.onEnter(self.txt)
        end
    end
    
    function Input:splitAndDrop(dropCount)
        local head = string.sub(self.txt, 0, self.pos - dropCount)
        local tail = string.sub(self.txt, self.pos + 1)
        return head,tail
    end
    
    function Input:blur()
        self.focus = false
        hideKeyboard()
    end
    
    function Input:visiblePart()
        local winSize = self:winSize()
        return string.sub(self.txt, self.winPos + 1, self.winPos + winSize)
    end
    
    function Input:winSize()
        font(self.fontName)
        local winSize = string.len(self.txt)
        local part = string.sub(self.txt, self.winPos, self.winPos + winSize)
        local w,_ = textSize(part)
        while w > self.w do
            winSize = winSize - 1
            part = string.sub(self.txt, self.winPos, self.winPos + winSize)
            w,_ = textSize(part)
        end
        return winSize
    end
    
    function Input:draw()
        pushMatrix()
            translate(self.x, self.y)
            pushStyle()
                self:showBox()
                self:showText()
                self:posCursor()
                if self.focus then
                    self:showBorder()
                    self.cursor:draw()
                end
            popStyle()
        popMatrix()
    end
    
    function Input:showBox()
        fill(255, 255, 255, 255)
        stroke(255, 255, 255, 255)
        strokeWidth(padding)
        rect(-padding, -padding, self.w+2*padding, self.h+2*padding)
    end
    
    function Input:showBorder()
        noFill()
        strokeWidth(2)
        stroke(127, 127, 127, 255)
        rect(-padding, -padding, self.w+2*padding, self.h+2*padding)
    end
    
    
    function Input:showText()
        font(self.fontName)
        textMode(CORNER)
        fill(0, 0, 0, 255)
        text(self:visiblePart(), 0, 0)
    end
    
    function Input:touched(touch)
        if self:contains(touch) then
            self.focus = true
            if not isKeyboardShowing() then
                showKeyboard()
            end
            if touch.state ~= ENDED then
                self:moveCursor(touch.x)
            end
        else
            self.focus = false
        end
    end
    
    function Input:contains(touch)
        return self.x <= touch.x 
            and touch.x <= (self.x + self.w)
            and self.y <= touch.y 
            and touch.y <= (self.y + self.h)
    end
    
    function Input:moveCursor(x)
        pushStyle()
            font(self.fontName)
            local min = math.huge
            local part = self:visiblePart()
            for i = 0,string.len(part) do
                local sub = string.sub(part, 0, i)
                local w,_ = textSize(sub)
                local dist = math.abs(x - (self.x + w))
                if dist < min then
                    min = dist
                    self.pos = self.winPos + i
                end
            end
        popStyle()
        local rightEnd = self.winPos + self:winSize()
        if self.pos == self.winPos and self.winPos > 0 then
            self.winPos = self.winPos - 1
        elseif self.pos == rightEnd and rightEnd < string.len(self.txt) then
            self.winPos = self.winPos + 1
        end
        self:posCursor()
    end
    
    function Input:posCursor()
        pushStyle()
            font(self.fontName)
            local part = self:visiblePart()
            local relPos = self.pos - self.winPos
            local sub = string.sub(part, 0, relPos)
            self.cursor.x,_ = textSize(sub)
        popStyle()
    end
    
    Cursor = class()
    
    function Cursor:init(h)
        self.h = h
        self.x = 0
        self.show = true
        tween.delay(0.4, Cursor._blink, self)
    end
    
    function Cursor:draw()
        if self.show then
            pushStyle()
                strokeWidth(3)
                stroke(0, 0, 0, 255)
                line(self.x, 0, self.x, self.h)
            popStyle()
        end
    end
    
    function Cursor._blink(cursor)
        cursor.show = not cursor.show
        tween.delay(0.4, Cursor._blink, cursor)
    end
    
  • Posts: 502

    is multiline also possible? havent tried yet..

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @LightDye ok i managed to copy the code anyway.
    Feedback: this is excellent work: quick and lean! Thanks for sharing!
    Maybe a small improvement would make it perfect: moving the string when bigger than the box is not perfectly easy: the text stops moving sometimes.

  • Omg i wanted to release something like this as well, but I just don't have time to work on it right now :o xD

    but nice job @LightDye

  • Posts: 355

    @se24vad hello!!

    Do you want to put the code in CC please . is that right now I'm on the ipad, and I want to see what the code, but I can not copy . Thanks :)

  • dave1707dave1707 Mod
    Posts: 7,803

    @Jmv38 How did you manage to copy the code. On my iPad 1, I can't seem to grab anything to copy.

  • edited November 2013 Posts: 355

    no matter, I could copy @se24vad

    @dave1707. guess I did not copy it, but touch the screen several times until I could do it, a little strange

  • dave1707dave1707 Mod
    Posts: 7,803

    @Luismi @Jmv38 I figured out how to copy it. I long press in the text above the code. When I get a little copy area ,I then drag my finger down into the code and move it around until it selects all of the code.

  • Posts: 355

    is a little strange no ? @dave1707

  • dave1707dave1707 Mod
    Posts: 7,803

    @Luismi I like code that's posted with 3 ~'s before and after the code. That's the easiest to copy.

  • Posts: 355

    oh yea of course :)

  • Thanks for the comments. I wasn't aware that colouring cause difficulties to copy the code. I just removed it to make it easier for those who haven't been able to copy it yet. I'll have a look later how to publish through Codea Comunity, because I haven't use the service yet.

    @se24vad Unfortunately this code is not multiline capable.

    @Jmv38 You are right, I'll see what I can do to prevent the intermitent pauses.

  • Posts: 2,042

    Emoji does not work. 1) It appears blacked out 2) It messes up the touch to move and cursor placement.

  • edited November 2013 Posts: 547

    @JakAttak Emoji doesn't work is for this simple reason: for emoji the fill should be set to 'white' so that's rather hard to incoorporate into a black text textbox
    And the movement of the emoji is... emoji is multiple chars long, so the string sees this not as an emoji and thus the width of the emoji, but it sees it as the seperate chars.
    A solution would be to use tables instead of string, but that still doesn't solve the blacked out.

    But when I get some spare time, I'll continiue on my textbox which uses tables, multiline, wordwrap

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @dave1707 i used the same trick as you to copy the code!

  • Posts: 1,976

    The caret stays flashing if you press the hide keyboard button.

  • @SkyTheCoder, if you want that behaviour all you need to do is adding this snippet at the begining of the Input:draw()

        if not isKeyboardShowing() then
            self:blur()
        end
    
  • Code is now available in Codea Community.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @LightDye i used your code for my next version of XFC. Thanks!

  • @Jmv38 - You are welcome! When I have the chance I'll add licensing terms. I think LGPL or the like so that anyone can use it freely.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @LightDye licencing terms is a good topic! I would like:
    - to use code from others (when they agree).
    - to share my code with codea users so they can use freely the functionnalities of the program, without restrictions,
    - to keep some rights if the code itself is copied in a commercial app. At least the the user should mention he uses my code, in a 'credits' section for instance, and tells me he does, so i can use this to promote my skills.
    Do you think this possible? What knind of licence should i use then?

  • edited November 2013 Posts: 57

    @Jmv38 - I use open source all the time and I'd like to give back too, but to be honest I don't know all the details about licenses. I'd go with something like LGPL that allows you to use the code in commercial products for free, or something like Creative Commons attribution (by) which is also very liberal.

  • IgnatzIgnatz Mod
    Posts: 5,396

    I think it would be a good idea to share this info in the wiki so people know the best way to license their code. Because, sure enough, someone is one day going to abuse our trust and the way we share freely.

  • I've chosen Creative Commons Attribution (http://creativecommons.org/licenses/by/3.0/au/) for this work and updated the code accordingly in Codea Community.

  • @LightDye can you tell me why you're using underscores in function names, for example:

    function Input._touched(touch)

    I notice you also call those functions using dot notation and not colons. Why is that?

    Oh yeah, also: awesome code!

  • Hi @UberGoober, and thanks. It's been a year since I wrote that code and I had to check it out to reply. I rarely find time to code in Codea these days.

    I used the underscores to prefix class functions (functions that can be called without creating an object of the class, i.e. invoked in a "static" context). The dot notation is used to invoke a class function, whereas colons are used to invoke instance functions, i.e. functions that run in the context of an object which is just an instance of the class.

    Since the visual difference between a dot and a colon is subtle, I prefixed class functions with underscores just to make the difference more obvious. Other than that, there is no real need for the underscores. I could have chosen to name class functions with an initial capital letter, for example.

  • Posts: 77

    Just curious-could you explain how you did the cursor processing to work with non-monospaced fonts? I'm writing my own textboxes, but they only support one specific font.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @FLCode - the textSize function tells you how wide and tall any piece of text is, which will help you position the cursor

  • Hi @FlCode, exactly as @Ignatz pointed out, the TextSize function is used in Input:posCursor() after calculating the portion of text that is currently visible in the field.

  • Is there a way to tell the height of the keyboard, so that we can mimic Apple's "slide stuff up if the keyboard covers it" animation?

  • Posts: 688

    @Jmv38 - Really useful bit of code, thanks :)

  • How can I save the input text? Can anybody help!

  • dave1707dave1707 Mod
    Posts: 7,803

    @calinefrangieh This discussion is a year to 2 years old. There are newer discussions that deal with text input and I'm not sure if anyone is going to look thru this code to answer you. But someone might.

  • dave1707dave1707 Mod
    Posts: 7,803

    @calinefrangieh Are you looking for help on this particular code, or are you interested on how to get input from a simple text area.

  • @dave1707 no i am interrested in the second how o get input from a simple text area!!

  • @dave1707 can you help me find newer discussions please!

  • dave1707dave1707 Mod
    edited December 2015 Posts: 7,803

    @calinefrangieh Here's a simple example I had. If you have any questions, just ask.

    displayMode(FULLSCREEN)
    supportedOrientations(PORTRAIT_ANY)
    
    function setup()
        inp=1    
        var1,var2,str="","",""
        bcolor= 0
        x=300
        y=500
        w=200
        h=50
        l=x-w/2    --button left
        r=x+w/2    --right
        b=y-h/2    --bottom
        t=y+h/2    --top
        rectMode(CENTER) 
    end
    
    function draw()
        background(30,30,0,255)
        strokeWidth(6)
        fill(255)
        text("Tap button then input data",x,700)
        text("Press RETURN to show input",x,650)    
        text("Enter value",x,550)   
        if bcolor == 0 then
            fill(255, 0, 0, 255)
        else
            fill(128,0,0,255)
        end    
        rect(x,y,w,h)    -- input area        
        fill(255)
        if keyboardBuffer() ~= nil then
            text(keyboardBuffer(),x,500)    -- show data as it is keyed
        else
            text(str,x,500)    -- show data in input area  
        end  
        if inp==1 and str~="" then
            var1=str
            str=""
            inp=2
        end
        if inp==2 and str~="" then
            var2=str
            str=""
            inp=1
        end
        text(var1,x,HEIGHT-100)
        text(var2,x,HEIGHT-200)
    end
    
    function touched(tch) -- check if input area was touched
        if tch.x > l and tch.x < r then
            if tch.y > b and tch.y < t then
                showKeyboard()
                bcolor = 1
            end
        end
    end
    
    function keyboard(key) -- move keyboardBuffer to str when return is pressed
        if key == RETURN then
            str = keyboardBuffer()
            hideKeyboard()
            bcolor = 0
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 7,803

    @calinefrangieh Here's another example I had if you want something with multiple text input areas. There isn't a lot of editing of the input, so you can key something that will cause an error.

    displayMode(FULLSCREEN)
    
    function setup()
        rectMode(CENTER)
        tbTab={}
        table.insert(tbTab,textBox(WIDTH*.25,HEIGHT*.75,100,50,"Fahrenheit"))
        table.insert(tbTab,textBox(WIDTH*.75,HEIGHT*.75,100,50,"Centigrade"))
    end
    
    function draw()
        background(0)
        fill(255)
        text("Tap an input area and enter a value, then press return. ",WIDTH/2,HEIGHT-100)
        for a,b in pairs(tbTab) do
            b:draw()
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            for a,b in pairs(tbTab) do
                b:touched(t)
            end
        end
    end
    
    function keyboard(k)
        for a,b in pairs(tbTab) do
            if b.selected then
                b:keyboard(k)
            end
        end
    end
    
    textBox=class()
    
    function textBox:init(x,y,w,h,n)
        self.x=x
        self.y=y
        self.w=w
        self.h=h
        self.name=n
        self.str=""
        self.selected=false
    end
    
    function textBox:draw()
        fill(128,0,0)
        if self.selected then
            fill(255,0,0)
        end
        rect(self.x,self.y,self.w,self.h)   -- input area  
        fill(255)
        text(self.name,self.x,self.y+self.h)
        text(self.str,self.x,self.y)
    end
    
    function textBox:keyboard(k)
        if k==RETURN then
            hideKeyboard()
            if tbTab[1].selected then
                tbTab[2].str=string.format("%.2f",((tonumber(tbTab[1].str)-32)*5/9))
            end
            if tbTab[2].selected then
                tbTab[1].str=string.format("%.2f",(tonumber(tbTab[2].str)*9/5+32))
            end
            self.selected=false
        elseif k>="0" and k<="9" or k=="." or k=="-" then 
            self.str=self.str..k
        elseif k==BACKSPACE then
            self.str=string.sub(self.str,1,string.len(self.str)-1)
        end
    end
    
    function textBox:touched(t)
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and 
                t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
            showKeyboard()
            for a,b in pairs(tbTab) do
                b.selected=false
                b.str=""
            end
            self.selected=true
            self.str=""
        end
    end
    
  • @dave1707 why are you using ~?? And what should i add to be able to save the text?

  • Oh andd thanks a lot!!

  • dave1707dave1707 Mod
    Posts: 7,803

    @calinefrangieh The ~ in ~= is not equal. I think that's what you're referring to. It's hard to tell you how to save the text because I don't know what you want to do with it. In my first example, the text is being put into str and then moved into var1 or var2 depending on which one I want to use. In my second example, the text is being saved in self.str .

  • edited December 2015 Posts: 45

    Can't i retain the variable1 in an array or a database?? Anddd thanks againnn

  • dave1707dave1707 Mod
    Posts: 7,803

    @calinefrangieh In my first example, str holds what is keyed in before I move it to either var1 or var2. So instead of str=keyboardBuffer(), you could save it in a table using table.insert(tab,keyboardBuffer()) or however you want to save it and not move it to var1 or var2.

  • Thankk youuu

  • edited October 7 Posts: 20

    @LightDye this is my editor, but it is not done yet :smile:

  • It's weird Codea doesnt provide real text input!

  • AnatolyAnatoly Mod
    Posts: 847
    its not weird! its just codea allows you the elementary freedom for your imagination
Sign In or Register to comment.