GetObject() by Id

  • #1, by darren-beckettFriday, 18. September 2015, 15:25 5 years ago
    Does anybody know how to call getObject() using an object id?

    I have the ID of the object i'm interested in stored in a variable and i now wish to retrieve that object, so i can then use it within Lua.

    Something like:

    myId = 160

    myObj = getObject("myId")

    1
    2
    3
    4
    5

    Great Poster

    351 Posts


  • #2, by sebastianFriday, 18. September 2015, 15:30 5 years ago
    objects are saved in a table and then have an id inside that table.
    tableid = 0
    objectid = 11
    getObject("(" .. tableid .. "," .. id .. ")")
    1
    2
    3

    Thread Captain

    2336 Posts

  • #3, by sebastianFriday, 18. September 2015, 15:33 5 years ago
    cant edit in mobile mode -.-
    "objectid" has to be "id" of course

    Thread Captain

    2336 Posts

  • #4, by afrlmeFriday, 18. September 2015, 15:56 5 years ago
    getObject() is actually explained on the scripting page of the wiki (near bottom of page).

    I'm not sure why you would want to access it like that though? It's a lot more confusing than the regular getObject() access method or the relatively new shorthand access method.

    What Sebastian wrote in is example shows you that you need to break the quote to be able to insert the id's into the getObject("path"), which is just as messy as typing out the words or variables themselves. On top of that... I'm not sure if it's possible to combine multiple id's together to create a full path?

    tid = game.SavedObject:getId().tableId -- store table id
    oid = game.SavedObject:getId().id -- store object id

    offset = getObject("(" .. tid .. "," .. oid .. ").ObjectOffset")
    print( offset.x, offset.y )
    1
    2
    3
    4
    5
    6

    vs ...
    offset = game.SavedObject.Offset
    print( offset.x, offset.y )
    1
    2
    3


    Personally I like to keep things simple. I don't have the best of memory so being able to type in English is great for me as it allows me to quickly read over my scripts & -- comments to see what's what. But each to their own! wink

    Imperator

    6805 Posts

  • #5, by darren-beckettFriday, 18. September 2015, 16:08 5 years ago
    Thanks guys.

    Great Poster

    351 Posts

  • #6, by sebastianFriday, 18. September 2015, 19:12 5 years ago
    the only way which makes sense to me to use this objectid method is when you want to access a specific object but the objectname changes while developing the game and you dont want to edit it always.

    (like accessing dialogparts where the dialogoptions are used as the objectname. so when changing a dialogtext these get changed, too. Also they are really long. )

    Thread Captain

    2336 Posts

Write post