(Table issue) Using a variable to allocate a table value

Hi, I want to use a variable ( [text]game.tableName ) to allocate a table value with function tableCellValue( game.tableName, row, col ), but it is failure.
Is there any way to do this?
Is there any way to do this?
Best Answer
-
pinata14 Posts: 150
to my knowledge, you would have to make rules for every table that could be loaded, but when writable tables come out you could do this using tables
Answers
If so the way you would combine text and attributes is this
"text"..game.tableName
Hope that helps. If not please explain a little more what you are trying to do.
Cheers
could you explain how to use that? i think it might be useful later on for me
In detail, I want to do this:
----------------------
I have 100 tables:
[Table1]
[Table2]
[Table3]
[Table4]
.
.
.
[Table100]
----------------------
I want to load table (smartly) with a variable (like [Index] in C,C++,,Java...etc).
When I want to load different table, I only need to change the index value:
1.
game.attribute.index = "TabeleN" (Table1~Table100)
2.
and using function :
tableCellValue( game.attribute.index, row, col )
That's what I want to do : )
If you have image files named 1.png, 2.png, 3.png, etc., you can use change attribute self.Image to [some attribute name]..".png". This is used for custom fonts because you can constrain self.Image to the value of an integer attribute and when that attribute changes, the image changes to a 1 or 2 or 3 (assuming 1.png is actually a picture of a 1).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
tableCellValue will only take a table as first argument.
A trick to do you the effect is to use rule... this is not what I would call smart (it is rather brute force) but I would make the same render.
You store the number between 1 to 100 into an attribute and then you have rules to compare this attribute, if attribute is 1, then use table 1, otherwise if....
Always include the next rule in the otherwise section of the previous rule as it will save some processing time.
David
If the table is small enough say like 2 columns wide or 2 rows down you could always just put all of your tables together then just change the column number.
say for example.... tableCellValue(game.Table1, [insert row number], (game.level-1)*x+n)
so..
game.level = the level the user is on
x = the number of columns allocated for each level (say you have a pos.X and a pos.Y then x=2)
n = the column you're looking for within the number of columns allocated for each level (if pos.X is the first column in the series of 2 the n=1 if its the 100th column for that level then n=100)
Hope that helps!
-Aaron
EDIT: this could work for any size table, small ones would be easier to manage tho