Hey there,
So I’m trying to get a basic version of autocomplete working, but I’m falling down trying to get a function to read the table…
I’ve got a couple of letters that when tapped display into a text box (via a laborious function), and I want to make it so that when the text box reads a certain value then an image will appear…
For example, “AABB” will show image “nicoll”…
My code is below… I’ve tried making it a clickable button, but it’s still nothing appearing so far… even a ‘print’ value isn’t showing that the value is there… similarly, I’ve tried asking it to check the newText without success…
local function stationShow( event ) if (theWordText== "AABB") then nicoll.isVisible = true print( "Nicoll show" )
Any help would be greatly appreciated…
local composer = require( "composer" ) local scene = composer.newScene() local widget = require ( "widget" ) local chosenLetters = {} theWord = '' theWordText = "" function scene:create( event ) local sceneGroup = self.view letterGroup = display.newGroup() sceneGroup:insert( letterGroup ) stationGroup = display.newGroup() sceneGroup:insert( stationGroup ) local letterA = display.newImageRect ( letterGroup, "images/anton\_54.png", 200, 200) letterA.x = 200 letterA.y = 200 letterA.id = 1 local letterB = display.newImageRect ( letterGroup, "images/anton\_61.png", 200, 200) letterB.x = 400 letterB.y = 200 letterB.id = 2 local letterC = display.newImageRect ( letterGroup, "images/anton\_28.png", 200, 200) letterC.x = 600 letterC.y = 200 local theWordText = display.newText("",500,437,native.systemFontBold,50) theWordText:setTextColor( 1, 1, 1 ) local function formStringA( event ) if ( event.target.id == 1 ) then local theLetter = "A" print( "letterID: " .. event.target.id ) table.insert(chosenLetters,theLetter) theWord = theWord .. theLetter theWordText.text = theWord theWordText.x = display.contentWidth/2 elseif ( event.target.id == 2 ) then local theLetter = "B" print( "letterID: " .. event.target.id ) table.insert(chosenLetters,theLetter) theWord = theWord .. theLetter theWordText.text = theWord theWordText.x = display.contentWidth/2 end return true end local function reset( event ) if ( event.phase == "began" ) then theWord = '' theWordText.text = "" elseif ( event.phase == "ended" ) then print( "Letters reset" ) end return true end local nicoll = display.newImageRect ( stationGroup, "images/nicoll.png", 200, 200) nicoll.x = 200 nicoll.y = 600 nicoll.isVisible = false local function stationShow( event ) if (chosenLetters == "AABB") then nicoll.isVisible = true print( "Nicoll show" ) return true end end stationShow() letterA:addEventListener( "tap",formStringA ) letterB:addEventListener( "tap",formStringA ) letterC:addEventListener( "touch", reset) end