Weird String compare bug...
by Nic Cusworth · in Technical Issues · 12/12/2006 (4:35 am) · 2 replies
I'm new to TGB so this might be a really stupid mistake, but I'm puzzling over a little but of code and why it doesn't work.
I'm reading in a simple text file that stores some level data. It was reading in fine and working as expected. However, today I decided to change the code to I could index levels in the text file.
The format is very simple:
LEVEL:1
[data]
LEVEL:2
[data]
etc...
I have a global variable called $currentLevel
here's the code:
if(%file.openForRead("./data.txt"))
{
%line = %file.readLine();
if (%line == "LEVEL:" @ $currentLevel)
{
.......
So what I want to do is check the read in %line to see if it equals 'LEVEL:1', 'LEVEL:2' etc...
However - it always returns true. Doesn't matter if $currentLevel equals 2 or 200, it will still return true when it reads 'LEVEL:1' from the file.
Please help.
Nic.
I'm reading in a simple text file that stores some level data. It was reading in fine and working as expected. However, today I decided to change the code to I could index levels in the text file.
The format is very simple:
LEVEL:1
[data]
LEVEL:2
[data]
etc...
I have a global variable called $currentLevel
here's the code:
if(%file.openForRead("./data.txt"))
{
%line = %file.readLine();
if (%line == "LEVEL:" @ $currentLevel)
{
.......
So what I want to do is check the read in %line to see if it equals 'LEVEL:1', 'LEVEL:2' etc...
However - it always returns true. Doesn't matter if $currentLevel equals 2 or 200, it will still return true when it reads 'LEVEL:1' from the file.
Please help.
Nic.
About the author
Torque 3D Owner Caylo Gypsyblood
Oh and $ before a variable is for GLOBAL, and %variable = local. $ do not define it as a string, any variable can be of any type.