Modding Discussion Problem with callScript on world.monsterQuery

Discussion in 'Starbound Modding' started by lonesurvivor, Dec 9, 2013.

  1. lonesurvivor

    lonesurvivor Big Damn Hero

    I tried to script some interaction between my tech mod and monsters. I tried a lot of different thing, but i can't get it to work.

    What I did:

    I used world.monsterQuery in my techmod.lua file to scan a given area for monster entities (see here https://gist.github.com/jordoh/7864154). The function returns a table of the entityId's of the entities in the area. This works very well. The problems begin when I try to use the callScript option, which should execute a given function on the targets script. If you look for example into assets/monsters/unique/penguinUfo/behavior.lua, you can see on line 94:

    Code:
      return world.monsterQuery(min, max, { callScript = "isPenguinReinforcement" })
    which scans a given area for monsters and tries to call the function isPenguinReinforcement() on their lua script. This function is found in assets/monsters/unique/penguinUfo/penguin/behavior.lua and assets/monsters/unique/penguinUfo/penguinTank/behavior.lua. And it works (of course). I tested it with some logging commands. So one monsters/npc can interact with other monsters/npc by these script calls. You can also find similar calls in the npc section.

    My Problem: If I try to use script calls from my tech lua script on some entities, the game gives me an access violation error and crashes. I spawned the UFO and tried to call the exact same function on one of the penguins as the UFO iself does. It doesn't work.

    Does someone know a way how to get this to work or another way to interact in a custom way between the player and monsters? Or is this just a bug? Or is it one of the things that is just not available yet to the modders?
     
  2. MorpH

    MorpH Subatomic Cosmonaut

    What does starbound.log say when it crashes?
     
  3. lonesurvivor

    lonesurvivor Big Damn Hero

    The log says:

    Code:
    Error: Access violation detected at 0x567b35 (Read of address 0)
    Error: Stack Trace...
      007D25B0 (C:/starbound/source/core/StarSignalHandler_windows.cpp:16)
      00567B35 (C:/starbound/source/game/StarMonster.cpp:878)
      007FE13F (C:/starbound/source/core/StarLua.cpp:694)
      00800330 (C:/starbound/source/core/StarLua.cpp:625)
      00831597 (C:/starbound/source/core/lua/ldo.c:320)
      00834CF2 (C:/starbound/source/core/lua/lvm.c:710)
      008319E8 (C:/starbound/source/core/lua/ldo.c:393)
      0080E749 (C:/starbound/source/core/lua/lapi.c:921)
      00831059 (C:/starbound/source/core/lua/ldo.c:134)
      00831C20 (C:/starbound/source/core/lua/ldo.c:591)
      0080FE91 (C:/starbound/source/core/lua/lapi.c:964)
      007FFA78 (C:/starbound/source/core/StarLua.cpp:666)
      007FFE22 (C:/starbound/source/core/StarLua.cpp:603)
      007FFEBC (C:/starbound/source/core/StarLua.cpp:342)
      ... (2)
      005249DF (C:/starbound/source/game/StarPlayer.cpp:657)
      004EE375 (C:/starbound/source/game/StarUniverseClient.cpp:201)
      00404C8B (C:/starbound/source/client/StarClientApplication.cpp:556)
      00407187 (C:/starbound/source/client/StarClientApplication.cpp:369)
      00409FE4 (C:/starbound/source/application/StarApplicationBase.cpp:199)
      00407A0F (C:/starbound/source/client/main.cpp:49)
      004DB571 (c:\SDL-1.2.15/./src/main/win32/SDL_win32_main.c:318)

    Looks like a memory error. Maybe the script is just not allowed to access this memory area. So it may be a bug?
     
  4. kieve

    kieve Intergalactic Tourist

    I'm trying to get Techs to communicate with objects (seeing as only Techs can interact with the player).
    This access error is happening for me too. I have a feeling that techs, monsters, the player, etc are running in sandboxes. Completely separate from each other.
    More precisely, from a tech object perspective, monsters don't exists. They're "entities". So any function defined on a "monster" with that id, doesn't exist in the world of techs.

    Supporting my theory on multiple sandboxes:
    If you attach a property to the global math library (Example: math["TEST"] = "I'm here") from an object (such as a wire switch), all objects will be able to read that property. For a tech? It would be null.
     
  5. lonesurvivor

    lonesurvivor Big Damn Hero

    Yep exactly. I tried that too. I tried a lot of other stuff, nothing worked. They are completely separated.

    But finally I found a "hack" around by exploiting NPC spawning, and I used it in my telekinesis mod: http://community.playstarbound.com/...kinesis-tech-drag-and-drop-your-enemies.46579

    The point is, NPC's can actually interact with other NPC's and monsters. So thought, why not spawn invisible NPCs to communicate with the monster entities? I tried it and it works. The only problem is, that you need a way to transmit the data you want to give to the monster entity via. In my case, it was pretty easy. There are three known parameters you can choose in the spawn command and access from the npc itself: x position, y position and level. I used x and y to transmit the position of the mouse, and the level to determine if you are clicking, holding the button or releasing it.

    The NPC can then work as a relay. It determines from the given parameters which function on the target monsters to call and where to do the monsterQuery. In my case it was just the position of the mousepointer, and the level (1,2 or 3) determines if you call the grab function, the hold function or the release function in the monster script. This way I achieved to grab the monster with the mouse, drag it around and drop it with using a tech.

    It is important that the invisible NPC dies immediately after spawning, or you will get a lot of entities in your game... Therefore I just set the health parameter in the npctype file to zero.

    If you want to try it, just look at my mod.

    Edit: I Made a little tutorial for it: http://community.playstarbound.com/...action-between-the-player-and-entities.47852/
     
    Last edited: Dec 11, 2013
    Supergeek likes this.
  6. Supergeek

    Supergeek Scruffy Nerf-Herder

    That is a very clever kludge, kudos. We can create a new NPC type that doesn't move around or do anything, and use them for data storage.
     
    lonesurvivor likes this.

Share This Page