Back to General discussions forum
Hi. I've implemented the game and it runs smoothly on my machine (using the JITLua program). However, when I run it on the C.A. site, it yields "lost" in the answer box, right after the "ready" part. Not sure why this is happening and if I'm supposed to interact with the box somehow. As I mentioned earlier, the script works fine on my computer. Thanks
I think the problem might be here:
local x = io.read('*n')
local y = io.read('*n')
if x and y then
x = tonumber(x)
y = tonumber(y)
...
endif
io.read('*n') already returns an integer, so you may not want to cast the result of this function using tonumber.
Also, some solutions insert math.randomseed(os.time()) somewhere in the beginning. I don't think it's required but it won't hurt either.
Additionally, try removing this if x and y check altogether.
I see. Many thanks for your feedback! Lua is still new to me, but I'm learning. I'll revise my code later. Thanks
Hm, this thread reminded me of some amendment I made for Lua interpreter a couple of months ago - it was to address the lack of compound assignment, unusual inequality operator (I remember our colleague Clive expressed our common feeling of how confusing these are) and perhaps something else. It seems like the amended version is used in the "browser version" of Lua on this site, but not in the "Sandbox" yet. So let this be a note to me to update the latter too.