1
votes

For some reason, this code returns nil

file = io.open("file.txt","r+") 
thingfulthink = io.read('*all')
print(thinkfulthing)

also if I try to compare that variable (thinkfulthing) an error jumps with the legend: error, can't compare number with 'nil'

Sorry if it's hard to read but I have the whole code in my pc and I'm writing from the phone, I'll edit tomorrow to add the full code

--edit

Also the file looks like this

200

And I tried using Python to open and read the file and it does return 200 as expected

file = open("file.txt", "r,")
thingfulthink = file.read()
print(thinkfulthing)
1
Note the difference between line 2 in both programs. - lhf

1 Answers

2
votes

Use file:read('*all') instead of io.read('*all').