The problem is the if statements - if you press button 4 the state becomes 'two' but then you're immediately checking the state again . As the state is now 'two' it becomes 'three' and so on. So, in a single pass of TIC() your state goes 1->2->3->1 so it always prints as state one. The fix is to use 'else' clauses like this:
state = "one"
function TIC()
cls(0)
if btnp(4) then
if state == "one" then
state = "two"
elseif state == "two" then
state = "three"
elseif state == "three" then
state = "one"
end end
if state == "one" then
print("First state",0,0)
elseif state == "two" then
print("Second state",0,0)
elseif state == "three" then
print("Third state",0,0)
end
end
I guess you'd also want to use btnp() as I've indicated otherwise the program will cycle through the states very quickly (try it, using trace() instead of print to see the state changing) - probably not what you want!