This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
proxene's profile picture

Conditional statements

Started by proxene, 15 May 2016 - 08:27 AM
proxene #1
Posted 15 May 2016 - 10:27 AM
Hi , I have a problem with conditional statements .

If I for example $1000 in my bank account, I can not transfer this amount but if I have $ 999 I can.

http://pastebin.com/Vsb3Cv3A ( line 115 )

Can you help me ?
thank you in advance

Regards ,
Proxene
Bomb Bloke #2
Posted 15 May 2016 - 11:32 AM
Data read from text-mode file handles comes in the form of strings. You can't compare strings directly against numbers, but if the string contents represent numbers, then you can convert types:

bal2 = tonumber(h.readAll())

When comparing strings against strings, than alphabetical ordering is used to get the results.

1000 > 999      --# true
"1000" > "999"  --# false
Edited on 15 May 2016 - 09:34 AM
proxene #3
Posted 15 May 2016 - 11:42 AM
Okay thank you so much :)/>