简体   繁体   中英

Lua will not accept user input when using io.read() [using Touch Lua iOS application]

I'm attempting to program a Simon Says game in Lua, using the Touch Lua application by Hawwash-Soft for iOS 7+. I'm using the iPhone version on an iPad Mini.

My problem is that near the end of my code, I have an io.read() thing that won't accept user input. If I attempt to type anything, it simply doesn't show up. The program is stuck there until I stop it.

Here's the code:

clear()
local file=io.open('Simon Says Memory.lua','w')
file:write()
file:close()
print('Hello World!')
sleep(2000)
clear()
repeat
   num=math.random(4)
   color='t'
   wait=1000
   if num==1 then color='red '
   elseif num==2 then color='green '
   elseif num==3 then color='yellow '
   elseif num==4 then color='blue '
   end
   local file=io.open('Simon Says Memory.lua','a+')
   file:write(color)
   file:close()
   local file=io.open('Simon Says Memory.lua','r')
   colors=file:read("*a")
   file:close()
   print(colors)
   sleep(wait)
   clear()
   wait=wait+1
   colorsin=io.read()
until colorsin~=colors
print('Game Over!')

Here's what generally outputs when I run the program. I'll use red for the random color. I'll put notes, for example if the screen is cleared, in []s.

Hello world!
[waits 2 seconds]
[screen clears]
red
[waits 1 second]
[clears]
[cursor appears]

I am unable to type anything with the cursor, no matter how many virtual keys I press. My typing simply doesn't show up.

Thanks in advance.

Edit: I worked out where io.read() starts getting stuck. I put a few dummy io.read() things throughout the code, and they worked until just after the second clear(). I have no clue why...

I figured it out, in case anyone comes upon this and has this question. There needed to be a print statement between the clear() and the io.read().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM