Modding Help Reading Parameters like its name from objects

Discussion in 'Starbound Modding' started by madtulip, Dec 21, 2013.

  1. madtulip

    madtulip Phantasmal Quasar

    Hello guys. I wanted to know which obejcts are in the vicinity and what theire names are. I couldnt solve this so far.

    So what i did is this.:
    Code:
    world.logInfo ("----------START---------");
        world.logInfo ("My name is:");
    -- validate syntax in the current content
        world.logInfo (object.configParameter("objectName"));
        world.logInfo ("your names are:");
        local ObjectIds = world.objectQuery (object.toAbsolutePosition({ 0.0, 0.0 }), 1000);
        for _, ObjectId in pairs(ObjectIds) do
            -- try same syntax in the context of another object
            if ((world.callScriptedEntity(ObjectId, "object.configParameter", "objectName")) ~= nil) then
                -- if we reach this spot it did work
                world.logInfo(world.callScriptedEntity(ObjectId, "object.configParameter", "objectName"));
            else
                -- if we come out here it did not work
                world.logInfo("name is nil");
            end
        end
    world.logInfo ("----------END---------");
    So lets take a look at the console out.:
    Code:
    Info: ----------START---------
    Info: My name is:
    Info: madtulip_scanner    <----- this was called from the calling objects context and prooves correct syntax
    Info: your names are:
    Info: name is nil                <----- this shows that i can not invoke "object.configParameter" in the context of this object of type A
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: madtulip_scanner   <----- this shows that i can invoke "object.configParameter" in the context of this object of type B
    Info: name is nil
    Info: name is nil
    Info: madtulip_shipdoor
    Info: name is nil
    Info: madtulip_life_support_system
    Info: madtulip_vent
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: madtulip_shipdoor
    Info: name is nil
    Info: madtulip_vent
    Info: madtulip_vent
    Info: name is nil
    Info: name is nil
    Info: ----------END---------
    So where is the difference between object type A and type B ? all objects of type B have in theire .object code.:
    Code:
      "scripts" : [ "<path_to_some_script>.lua" ],
      "scriptDelta" :  <some int value>
    some .lua script initialization. the objects of type A do not have a script. So if those objects would have a script defined which has no additional content (main beeing empty apart from constructor), only then they would have an instance of the "object." and "world." context. That most probably is just because objects without a "scirpts" in theire .object file have no .lua functionality at all.

    So how else can i get to the content of a .object JSON datastructure if not by finding its ID and then calling its context by "world.callScriptedEntity" ? "world.get_configParameter_of_entity (ID,ParameterName)" would be my suggestion, as it seems a lot simpler then creating a lua enviroment for every object and calling its context by using "world.callScriptedEntity", but that doesnt seem to exists.

    Requesting:
    world.get_configParameter_of_entity (ID,ParameterName)

    or is there a different solution? i dont get it.
     
  2. madtulip

    madtulip Phantasmal Quasar

    No, objects must have a unique name defined in theire .object file by using the parameter
    Code:
    "objectName" : "madtulip_uba_object"
    this is just not accessible if they dont ALSO have a .lua script which totaly doesnt make sense.
     
  3. Westeller

    Westeller Space Penguin Leader

    Yea, I realized that as soon as I posted it, and deleted my post. You caught it too fast.
    Anyway, when I run this on my ship:


    Code:
    Info: ----------START---------
    Info: My name is:
    Info: ubspawner
    Info: your names are:
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Info: name is nil
    Error: Access violation detected at 0x7581d5 (Read of address 0)
    Error: Stack Trace...
      007DEE70 (C:/starbound/source/core/StarSignalHandler_windows.cpp:16)
      007581D5 (C:/starbound/source/game/objects/StarWireObject.cpp:482)
      ... (3)
      0080CB0F (C:/starbound/source/core/StarLua.cpp:691)
      0080F000 (C:/starbound/source/core/StarLua.cpp:625)
      00840277 (C:/starbound/source/core/lua/ldo.c:320)
      008439D2 (C:/starbound/source/core/lua/lvm.c:710)
      008406C8 (C:/starbound/source/core/lua/ldo.c:393)
      0081D429 (C:/starbound/source/core/lua/lapi.c:921)
      0083FD39 (C:/starbound/source/core/lua/ldo.c:134)
      00840900 (C:/starbound/source/core/lua/ldo.c:591)
      0081EB71 (C:/starbound/source/core/lua/lapi.c:964)
      0080E0B2 (C:/starbound/source/core/StarLua.cpp:663)
      0080E462 (C:/starbound/source/core/StarLua.cpp:603)
      0080E4FC (C:/starbound/source/core/StarLua.cpp:342)
      0075BB64 (C:/starbound/source/core/StarAny.hpp:488)
      006DFF88 (C:/starbound/source/game/StarItemUser.cpp:607)
      ... (3)
      00519DCC (C:/starbound/source/game/StarWorldClient.hpp:165)
      004F0735 (C:/starbound/source/game/StarUniverseClient.cpp:143)
      00404CFF (C:/starbound/source/client/StarClientApplication.cpp:559)
      00407357 (C:/starbound/source/client/StarClientApplication.cpp:368)
      0040A264 (C:/starbound/source/application/StarApplicationBase.cpp:199)
      00407C7F (C:/starbound/source/client/main.cpp:48)
      004DB931 (c:\SDL-1.2.15/./src/main/win32/SDL_win32_main.c:318)
    
    Info: Shutting down world alpha:44656612:16921790:-29929755:10:3
    Warn: Perf: UniverseServer::run.innerloop millis: 8696
    
    
     
    madtulip likes this.
  4. madtulip

    madtulip Phantasmal Quasar

    I would also like to add that only objects which have
    Code:
    "objectType" : "wire"
    in theire .object code will load scripts by
    Code:
    "scripts" : [ "<path_to_some_script>.lua" ],
      "scriptDelta" :  <some int value>
    which leeds to only objects of the wire type with .lua code have accessible names which is even better. Are you of the wire type?
     
  5. madtulip

    madtulip Phantasmal Quasar

    I have this additional mod installed. Cant reproduce youre error.
     
  6. Westeller

    Westeller Space Penguin Leader

    Yea. You're right.

    I did this:

    Code:
      local ObjectIds = world.objectQuery (object.position(), 1000)
      for _, ObjectId in pairs(ObjectIds) do
      world.logInfo(ObjectId)  
      world.callScriptedEntity(ObjectId, "object.smash")
      end
    
    Next to a wire object with a running .lua script, and next to a non-scripted object.
    Both the wire object and the object I used to call this script were destroyed.
    The non-scripted object just sat there unaffected.

    Scripts can't be called on objects that aren't using their own scripts.
     
  7. mrflippy

    mrflippy Lucky Number 13

    Well that explains why some of my scripts were behaving strangely. This also looks like it could be the case for queries like
    Code:
    world.objectQuery(position, distance, {name = "objectName"}
    Though I haven't confirmed this.

    Also, I've been doing testing from tech scripts, and there seems to be a delay before world.objectQuery returns results. At first I thought I was doing something wrong, but then I had my script wait a few update cycles and then the query worked.
     
  8. madtulip

    madtulip Phantasmal Quasar

    This are two different things.

    you can not call
    Code:
    world.callScriptedEntity
    on an object which doest have a script running. If it doesnt have its own scripts then it doesnt initialize its own instances of ... lua? there is basicaly no context of that object. thats why you cant call any lua functions in that not existing context. like object.smash.

    you can though call
    Code:
    world.objectQuery(position, distance, {name = "objectName"})
    which will return all objects (no matter if they have theire own script) which have the name property set to "objectName" (you filter for that). All objects have the name property and are known to world in principle no matter from where you call world. as world doesnt have a function that returns any property of an object which you only know by ID, like its name. i instead triied to go into the local context, which is possile and there use object. functions in that local context which can access the properties of the local object.

    In the 2nd case you call world from your local context. In the first case you first try to switch into the context of the other object by using
    Code:
    world.callScriptedEntity
    . This context doesnt exist at all and that is why you can not call world. or anything else inside that context.

    so as every world. can see every object there should be a world. function which can access all properties of all object kinds, even if they dont have lua scripts running so you dont even need to go into theire local context which in the end is just a dirty workaround which didnt work ... around.
     
  9. mrflippy

    mrflippy Lucky Number 13

    Did some more tests, and this worked for me. I guess I was using the wrong object names in my earlier tests.
     
  10. jordo

    jordo Aquatic Astronaut

    In Angry Koala, world.entityName will return the objectName from *.object for placed objects or the itemName from *.item for item drops.
     
  11. madtulip

    madtulip Phantasmal Quasar

    thanks jordo, much appreciated. I was already checking and am using that. I wonder thought why you create a get function specific for "objectName" and not a general one for all parameters an object or item has. It would be tedious and never complete to fill up all needed and "officialy supported" parameters. It would also not be very modable. A get function for one parameter suggest you are planning on keeping most things "private" on the variables side. On the other hand if the object is scripted you can access a callback function which can give you all parameters of the objects context which does fully speak against "private" methods in objects.

    This is why i was hoping/exspecting a general "world.get_entity_parameter(ID,Parametername)" and "world.set_entity_parameter(ID,Parametername)" comming this update.

    The callback is already such a great function! i just think its not feasable to equip every object that you might want to read from with a lua context and some get functions.

    Also and thats maybe a bit off topic there are still gaps in the interaction between .entity .tech storage shipworld and playerworld which can not be bridged. i dont understand a lua implementation on C++ side enought, but i would have exspected that .object and .tech inherit from the same class more to be less different. For the 2 different lua_states beeing initialized for planet and shipworld it would be relativly easy and already very helpfull if you could copy the "storage" object from the one in the other once you switch. Just some HDD so they are not compleetly seperated.

    Also when im at it already i had the impression (or messed something up) that a querry for objects and material in positions which have not yet been initialized (because no user did want to see that "chunk" of the world so far) are not beeing returned by the querry even if they are already set in that position on the map. i triied to set some "this is the shipworld flag objects or materials at position 1,1 of a large map but could access that from 1000,1000 for whatever reason. The objects init function of the object was executed though.

    Anyway. Very great patch for the lua side. A lot of stuff was done! Thanks a lot!
     
    Last edited: Dec 23, 2013

Share This Page