Referencing a table column by name

bjandthekatzbjandthekatz Orlando, FlMember Posts: 1,375

Hello, I am trying to call a table column based on an attribute. The attribute is the current level that the user is on and the column has multiple variations: 1type, 1x, 1y, 1w, and 1h because it holds the actors data. I was trying to use game.currentLevel.."x" and create all 5 rules to set the data, but it is showing up as 0 when called, not the correct table data. I saw somewhere that you have to use quotations when referencing a table name. How would I go about calling this data from the table? I have already tried currentLevel.."x", "currentLevel".."x" and "game.currentLevel..x"

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    There seems to be a problem with concatenating an integer to a text string. But if you do it the other way around it seems to work better.

    Example: "x"..self.currentLevel

  • tintrantintran Member Posts: 453
    edited July 2015

    I don't think we can reference tables by name, at least i can't on GS Windows.
    But your question is titled "referencing a table column by name" so is it column or table that you're having problems with.
    So i am confused not sure i understand your question.

  • bjandthekatzbjandthekatz Orlando, FlMember Posts: 1,375

    @RThurman said:
    If you do it the other way around it seems to work better.

    Example: "x"..self.currentLevel

    Wow, thank you very much! Should I submit a bug report or is it a known occurrence?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Its not exactly a bug. Its just how Lua deals with type conversion.

  • tintrantintran Member Posts: 453

    @RThurman said:
    Its not exactly a bug. Its just how Lua deals with type conversion.

    So you mention Lua so I looked it up and see how concatenation works.
    According to this documentation, "If any of its operands is a number, Lua converts that number to a string"
    http://www.lua.org/pil/3.4.html
    I think it might be a bug in Lua then

Sign In or Register to comment.