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

matt72228matt72228 Member Posts: 4
edited April 2012 in Working with GS (Mac)
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?

Best Answer

  • pinata14pinata14 Posts: 150
    Accepted Answer
    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

  • pinata14pinata14 Member Posts: 150
    what is the purpose of trying to use a text attribute? you can just choose the table variable right?
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Im not completly sure I understand. Are you wanting to display a piece of text that includes the value of an attribute?

    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

  • theCodeMonsterstheCodeMonsters Member Posts: 359
    edited April 2012
    GS is currently working on adding reading and writing to tables to do what your suggesting you need these things. So for now, you can't do what your talking about. (as I understand it)
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    edited April 2012
    LOL how funny this thread has been unanswered for over an hour then 3 of us replied within basically seconds of each other
  • pinata14pinata14 Member Posts: 150
    Im not completly sure I understand. Are you wanting to display a piece of text that includes the value of an attribute?

    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

    :O ive seen that used for "1"..png
    could you explain how to use that? i think it might be useful later on for me
  • matt72228matt72228 Member Posts: 4
    Thanks for reply :)

    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 : )
  • matt72228matt72228 Member Posts: 4
    Thank you :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    ive seen that used for "1"..png
    could you explain how to use that? i think it might be useful later on for me
    You can concatenate (join) two text attributes by using two periods between the attributes. If game.objectname is "door" and you change attribute game.objectname to game.objectname.."knob" then game.objectname will be "doorknob".

    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

  • guerinedguerined Member Posts: 11
    Hello Matt7228,

    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
  • aarioaario Member, PRO Posts: 256
    edited April 2012
    @matt72228

    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
Sign In or Register to comment.