Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

reading data from tables

bukai

Member

hiho,

l know how to read in a txt or write something into it,
but l dunno how l can read in .ods data sets(tables made with openoffice).
each row should be converted in an array so l could work with it.
the problem is it looks weird and messy when l print it.
my code
Code:
monstats = Array.new

File.open("Data/monstats.ods", "r+") do |save|

  monstats = save.readlines

end

  p monstats
http://img197.imageshack.us/i/messmof.jpg/
 
This formats are extremly complex. Look that you can unzip every openoffice document in a lot of other files. They use XML language.
You need to have a library for that or make your own based on the open specifications of the document.

It would be better for you to make your own formats. Something like this:
Wep| Drink| etc|
1| 1 | 2 | 3|
2|
3| etc|

In a plain TXT file. It can be better than write all in the scripts, i think. And you can make your own BD to edit that better, something like and extended version of the RPGXP BD. Or you can use some SQL like MySQL.
 

bukai

Member

ah ok, lm using a different editor now which is for txts.
now my array makes sense
but l still need help with my hash monstats. he's empty.
the first row of my table must be threated like a comment.
the array now:
http://img205.imageshack.us/i/monstatsraw.png/
my empty hash:
http://img55.imageshack.us/i/monstatsemptyhash.png/
l guess it has something todo with this regexp thing
Code:
 

monstats_raw = Array.new

File.open("Data/monstats.txt", "r+") do |save|

  monstats_raw = save.readlines

end

  p monstats_raw

monstats = Hash.new("")

monstats_raw.each do |row|

  if row =~ /\s*(\w+) \s* =\s*(\w+)\s*/x then

    first = $1

    second = $2

    monstats[first] = second

  end

end

  p monstats

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top