Modding Help [.lua code] help getting an object's position from world.objectQuery()

Discussion in 'Starbound Modding' started by cardstocks, Dec 13, 2013.

  1. cardstocks

    cardstocks Tentacle Wrangler

    Hey guys,
    I'm trying to dynamically get the position of a specific item by doing a query for it in the following code. I can get the object's entityID (or is it an objectID?) but then I can't figure out how to get the object's position from that. It seems very strange to me that world.objectQuery() wouldn't return the Object (with all of the data associated) of the object, but it doesn't. It returns a Lua table like this: [45] where '45' is the object's id # with name = "torch".

    I've tried doing stuff like 'table_name[1].location()' and stuff like that but nothing works. I get various errors boiling down to the program trying to read the index, [1], as an integer and not as an index...

    Lua is quite confusing.

    Any ideas?

    code:

    ---------------------------------------------------------------------------------
    torch_location = world.objectQuery(tech.position(), 5000, {name = "torch"})

    if world.entityExists(torch_location) then
    data.location = world.entityPosition(location)
    world.logInfo(data.location)​
    end
    ---------------------------------------------------------------------------------

    i'm getting my function calls from https://gist.github.com/jordoh/7864154
     
  2. kieve

    kieve Intergalactic Tourist

    Currently, there's no way to convert an object ID to an associated object.
    If they are an entity that can run LUA (like a wire object or something), you could save it's location in the _ENV variable. Then you could look it up by it's ID and see if it saved it's location. I don't know if it works with cross objects. (Like an NPC and a wire object, this is not possible with techs.).
     
  3. jordo

    jordo Aquatic Astronaut

    Couple things:

    1. world.*Query functions return a list of entity ids.
    Code:
    local objectIds = world.objectQuery(tech.position(), 5000, { name = "torch" })
    2. world.entityExists and world.entityPosition take single entity ids.
    3. world.*Query functions only return entities that exist.
    Code:
    if #objectIds > 0 then
      data.location = world.entityPosition(objectIds[1])
      world.logInfo("location is: %s", data.location)
    end
    
     
  4. jordo

    jordo Aquatic Astronaut

    The _ENV table is not guaranteed to be shared across contexts (e.g. between two different entities). Tech not being able to use world.callScriptedEntity will be addressed in the next update.
     

Share This Page