Quote from: nathmatt on July 23, 2012, 09:09:07 pm
@ForeverZer0 true but was bored so i made a class that would allow it
class Enhanced_Table
def initialize
@data = {}
end
def [](key1,key2=nil,key3=nil)
key = [key1,key2,key3].compact
return @data[key]
end
def []=(key1, key2, key3=nil, value=nil)
if value != nil
return @data[[key1,key2,key3]] = value
elsif key3 != nil
return @data[[key1,key2]] = key3
else
return @data[[key1]] = key2
end
end
end
so if i want to use this class i use Enhanced_
Table.new instead of
Table.new (and also making sure that the script is in my script list), nice, i honestly can not remember now why i was using strings for testing but i prefer flexibility, in case if i need to store an array of strings and strings can easily be converted to integers with .to_i (or was it .to_int)
Quote from: ForeverZer0 on July 23, 2012, 08:13:50 pm
KK20 is correct. I didn't notice you were attempting to place strings into a Table.
For normal function, there is no real advantage to using a Table anyway. A Table is simply a 1-dimensional C array of shorts. RMXP uses this only because Ruby's Array class is not fit to handle very large amounts of data, and you can get a slight performance increase when the amount of data is very large and accessed often.
In your case, if you need a container that is not so penalized for containing large amounts of data, just use a Hash. If performance is that critical where a Hash is not even acceptable in terms of perforamce, then you are using the wrong language.
using Table just seems easier to be easier to create blank multi-dimensional arrays which i populate with for loops or having a variable indicating the last index (if the variable is set to 5, then index 0 to 4 have data while all the rest are blank), with a normal array i think it's like
myArray1 = []
myArray2 = [[],[]]
myArray3 = [[[],[],[]],[[],[],[]]]
or something like that, i know the first differently works cause i use it in my Pandora Plugin Script before i go to import data from a file (i only ever used 1d arrays in that)
anyway, i'm not passing in huge arrays, all what needed to do is pass an array of indexs for an array created in a class to change the values of, insted of using
class.array[0] = 2
class.array[1] = 2
class.array[5] = 2
class.array[4] = 2
class.array[7] = 2
class.array[15] = 2
class.array[14] = 2
i pan to do this
indexArray = Table.new(7)
indexArray = [0,1,5,4,7,15,14]
class.changeArray(indexArray)
class class
classArray = Table.new(100)
def changeArray(array)
for i in 0...array.length
classArray[array[i]] = 2
end
end
end
the second is a hell lot neater and i'm less likely to forget what the hell i'm doing if i forget to document