我是相当新的编程,并想知道如果有人能在正确的方向指向我?
我试图把用户输入并用它来查找字典中的这个词如如果我输入“杰夫” ITLL看在字典,告诉我“12”,因为cluthaTable["jeff"] = "12";
cluthaTable = {};
cluthaTable["jeff"] = "12";
local defaultField
local function textListener( event )
if ( event.phase == "ended" or event.phase == "submitted" ) then
-- Output resulting text from "defaultField"
--print( event.target.text )
-- Saves the input as a var for looking up name
local test = event.target.text
print(test)
end
end
-- Create text field
defaultField = native.newTextField( 150, 150, 180, 30 )
defaultField:addEventListener( "userInput", textListener )
您是否尝试过这个吗?
local result = cluthaTable[event.target.text]
如果这样的关键存在于字典,这将是关键的值保存到结果变量。否则,结果变量将是零。