I'm trying to read some stuff from file. The file is set up in the following format
I'm able to read the file, but its not saving the section name(in the brackets) for the first section, every other detail and other section is fine. If i put the section in twice its fine
This is the code
I think its to do with the "if move.getInternalName != section" bit, but am unsure how to alter it.
What i'm trying to do is when the section changes, push the move into the array, then recreate the move to use again
[SectionA]
DisplayName=
Name=
[SectionB]
DisplayName=
Name=
I'm able to read the file, but its not saving the section name(in the brackets) for the first section, every other detail and other section is fine. If i put the section in twice its fine
This is the code
Code:
move = PSMove.new
file = File.new("DataFiles/moves.txt", "r")
while (line = file.gets)
line.delete! "\n"
line.delete! "\"\\"
if line[/^\s*\[\s*([a-zA-Z]+)\s*\]\s*$/]
section=$~[1] # The sections name contained in [x]
if move.getInternalName != section
moves.push(move)
move = PSMove.new
end
move.setInternalName(section)
else # Else of if line[/^\s*\[\s*([a-zA-Z]+)\s*\]\s*$/]
split = line.split("=")
if split[0] == "DisplayName"
move.setDisplayName(split[1])
end
end
end
moves.push(move)
I think its to do with the "if move.getInternalName != section" bit, but am unsure how to alter it.
What i'm trying to do is when the section changes, push the move into the array, then recreate the move to use again