Modding Help Critter behavior?

Discussion in 'Starbound Modding' started by Rufran, May 25, 2016.

  1. Rufran

    Rufran Phantasmal Quasar

    I've been trying to figure out how behaviors work for days and really have no idea what the restrictions are or if I need multiple behavior files. Plus, if I need multiple, how to specify that in the .monstertype?

    For the moment, I just want a critter that will wander around but runs from the player when they come near and playing a sound effect while fleeing.

    I've already tried a few patchwork attempts, but I will usually get errors regarding multiple parameters of the same type being defined. However, when I tried separating them by making them children, but then I get an error that children has already been defined. I know you can have multiple children, so I don't know what I am doing wrong in that regard.

    Please note that this is literally my first time using JSON or LUA and my previous programming experience never really got past syntax.

    I would really appreciate help.
     
  2. Inf_Wolf14

    Inf_Wolf14 Parsec Taste Tester

    First thing you could do is post your starbound.log file (Steam/steamapps/common/Starbound/giraffe_storage/...). That's essentially the most important file to look at when modding.
    Second, you could tell us is very specifically what you tried (What files in what places with what changes).

    Your best friend when figuring out what you did wrong is to check your log. 99% of the time that file tells you what is throwing errors.
     
  3. The | Suit

    The | Suit Agent S. Forum Moderator

    Personally speaking I would take the time to Lua properly before trying to take on such a task.
    https://www.lua.org/pil/contents.html

    JSON there really is nothing to learn, Lua on the other hand there is quite a bit.
    My personal favorite tutorial: http://www.phailed.me/2011/02/learn-lua-the-hard-way-1/

    You can also use this site https://repl.it/languages/lua
    to test basic scripts in the tutorial.
     
  4. Rufran

    Rufran Phantasmal Quasar

    Okay, so I have stepped through many iterations of this procedure, but I guess I'll start with my first attempt:

    Here is the relevant parts of the log file:

    [12:17:06.483] Error: Exception caught loading asset: /behaviors/monster/critter/gnome.behavior, (AssetException) Could not read JSON asset /behaviors/monster/critter/gnome.behavior
    [0] 7ff730d31933
    [1] 7ff730d2e2c8
    [2] 7ff730d2e3f8
    [3] 7ff73078b8e0
    [4] 7ff730ee952e
    [5] 7ff730e7e910
    [6] 7ff730e7b8b4
    [7] 7ffc6c3790e3 RtlCaptureContext
    [8] 7ff73078d6e2
    [9] 7ff7307852ef
    [10] 7ff730788d36
    [11] 7ff730786859
    [12] 7ff73078e8a6
    [13] 7ff7306daaa0
    [14] 7ff730784635
    [15] 7ff730783a68
    [16] 7ff73078384c
    [17] 7ff730783442
    [18] 7ff730783359
    [19] 7ff730d45c36
    [20] 7ff730d45f0d
    [21] 7ffc6a1a8102 BaseThreadInitThunk
    [22] 7ffc6c32c5b4 RtlUserThreadStart
    Caused by: (JsonParsingException) Cannot parse json file: /behaviors/monster/critter/gnome.behavior
    [0] 7ff730d31933
    [1] 7ff730d2e2c8
    [2] 7ff730d2e3f8
    [3] 7ff73078bb60
    [4] 7ff730ee7d32
    [5] 7ff730e7e910
    [6] 7ff730e7b8b4
    [7] 7ffc6c3790e3 RtlCaptureContext
    [8] 7ff7307827e5
    [9] 7ff73078d6e2
    [10] 7ff7307852ef
    [11] 7ff730788d36
    [12] 7ff730786859
    [13] 7ff73078e8a6
    [14] 7ff7306daaa0
    [15] 7ff730784635
    [16] 7ff730783a68
    [17] 7ff73078384c
    [18] 7ff730783442
    [19] 7ff730783359
    [20] 7ff730d45c36
    [21] 7ff730d45f0d
    [22] 7ffc6a1a8102 BaseThreadInitThunk
    [23] 7ffc6c32c5b4 RtlUserThreadStart
    Caused by: (JsonParsingException) Error parsing json: bad array, should be ',' or ']' at 85:19
    [0] 7ff730d31933
    [1] 7ff730d2e2c8
    [2] 7ff7307095a0
    [3] 7ff7307827e5
    [4] 7ff73078d6e2
    [5] 7ff7307852ef
    [6] 7ff730788d36
    [7] 7ff730786859
    [8] 7ff73078e8a6
    [9] 7ff7306daaa0
    [10] 7ff730784635
    [11] 7ff730783a68
    [12] 7ff73078384c
    [13] 7ff730783442
    [14] 7ff730783359
    [15] 7ff730d45c36
    [16] 7ff730d45f0d
    [17] 7ffc6a1a8102 BaseThreadInitThunk
    [18] 7ffc6c32c5b4 RtlUserThreadStart
    [12:17:06.487] Info: Loading DanceDatabase
    [12:17:06.489] Info: Done loading DanceDatabase in 0.00200009 seconds
    [12:17:06.489] Error: Exception raised during Root finishLoad: (StarException) Could not load behavior file '/behaviors/monster/critter/gnome.behavior'
    [0] 7ff730d31933
    [1] 7ff730d2e2c8
    [2] 7ff730d2e3f8
    [3] 7ff730d2dd10
    [4] 7ff730f39e15
    [5] 7ff730e7e910
    [6] 7ff730e7b8b4
    [7] 7ffc6c3790e3 RtlCaptureContext
    [8] 7ff730a6cff6
    [9] 7ff73070cf45
    [10] 7ff730709a7a
    [11] 7ff730706d52
    [12] 7ff7307087d0
    [13] 7ff7307096f9
    [14] 7ff73070910c
    [15] 7ff73070885e
    [16] 7ff73070872e
    [17] 7ff7307134b2
    [18] 7ff730d970ca
    [19] 7ff730d969d1
    [20] 7ff730d45f0d
    [21] 7ffc6a1a8102 BaseThreadInitThunk
    [22] 7ffc6c32c5b4 RtlUserThreadStart
    Caused by: (AssetException) Error loading asset /behaviors/monster/critter/gnome.behavior
    [0] 7ff730d31933
    [1] 7ff730d2e2c8
    [2] 7ff73078b825
    [3] 7ff730788436
    [4] 7ff7307831b4
    [5] 7ff73077f936
    [6] 7ff730a6cff6
    [7] 7ff73070cf45
    [8] 7ff730709a7a
    [9] 7ff730706d52
    [10] 7ff7307087d0
    [11] 7ff7307096f9
    [12] 7ff73070910c
    [13] 7ff73070885e
    [14] 7ff73070872e
    [15] 7ff7307134b2
    [16] 7ff730d970ca
    [17] 7ff730d969d1
    [18] 7ff730d45f0d
    [19] 7ffc6a1a8102 BaseThreadInitThunk
    [20] 7ffc6c32c5b4 RtlUserThreadStart
    [12:17:06.505] Info: Renderer destroyed
    [12:17:06.586] Info: Shutting down Star::Root
    [12:17:06.813] Error: Fatal Exception caught: (StarException) An error occurred during loading: (StarException) Could not load behavior file '/behaviors/monster/critter/gnome.behavior'
    Caused by: (AssetException) Error loading asset /behaviors/monster/critter/gnome.behavior


    Here is the offending file:

    {
    "name": "gnomecritter",
    "description": "",
    "scripts": [
    "/monsters/monster.lua",
    "/scripts/actions/time.lua",
    "/scripts/actions/movement.lua"
    ],
    "parameters": {},
    "root": {
    "title": "sequence",
    "type": "composite",
    "name": "sequence",
    "parameters": {
    "type": "sliding",
    "state": "off",
    "fromEntity": "attackTarget",
    "toEntity": "fleeTarget"
    },
    "children": [
    {
    "title": "setAnimationState",
    "type": "action",
    "name": "setAnimationState",
    "parameters": {
    "state": "idle",
    "type": "movement"
    }
    },
    {
    "title": "timer",
    "type": "action",
    "name": "timer",
    "parameters": {
    "time": [
    2,
    8
    ]
    }
    },
    {
    "title": "setDirection",
    "type": "action",
    "name": "setDirection",
    "parameters": {},
    "output": {
    "direction": "walk"
    }
    },
    {
    "title": "setAnimationState",
    "type": "action",
    "name": "setAnimationState",
    "parameters": {
    "state": "walk",
    "type": "movement"
    }
    },
    {
    "title": "parallel",
    "type": "composite",
    "name": "parallel",
    "parameters": {
    "fail": 1,
    "success": 1
    },
    "children": [
    {
    "title": "move",
    "type": "action",
    "name": "move",
    "parameters": {
    "direction": "walk",
    "run": false
    }
    },
    {
    "title": "timer",
    "type": "action",
    "name": "timer",
    "parameters": {
    "time": 4
    }
    },
    "children": [
    {
    "title": "entityExists",
    "type": "action",
    "name": "entityExists",
    "parameters": {
    "entity": "fleeTarget"
    }
    },
    {
    "title": "playernearby",
    "type": "action",
    "name": "playernearby",
    "parameters": {
    "entity": "fleeTarget",
    "range": 5,
    "position": "self"
    }
    },
    {
    "title": "entityInSight",
    "type": "action",
    "name": "entityInSight",
    "parameters": {
    "entity": "fleeTarget"
    }
    },
    {
    "title": "entityDirection",
    "type": "action",
    "name": "entityDirection",
    "parameters": {
    "target": "fleeTarget"
    },
    "output": {
    "direction": "moveDirection"
    }
    },
    {
    "title": "reverseDirection",
    "type": "action",
    "name": "reverseDirection",
    "parameters": {
    "direction": "moveDirection"
    },
    "output": {
    "direction": "moveDirection"
    }
    }
    ]
    },
    {
    "title": "",
    "type": "action",
    "name": "move",
    "parameters": {
    "direction": "moveDirection",
    "run": true
    }
    }
    ]
    },
    {
    "title": "timer",
    "type": "action",
    "name": "timer",
    "parameters": {
    "time": 5
    }
    }
    ]
    }
    ]
    }
    }


    So, from the log we can see that at at line 85, column 19 it claims there is a bad array. This JSON parser: http://json.parser.online.fr/ claims that there should be a comma in the line but that doesn't make any sense to me.

    This is the line:

    {
    "title": "timer",
    "type": "action",
    "name": "timer",
    "parameters": {
    "time": 4
    }
    },
    "children": [
    {
    "title": "entityExists",
    "type": "action",
    "name": "entityExists",
    "parameters": {
    "entity": "fleeTarget"
    }
    },

    If you compare this to the other uses of "children" there is no difference, so I don't know what it wants.
     
  5. Rufran

    Rufran Phantasmal Quasar

  6. Rufran

    Rufran Phantasmal Quasar

    While I am looking at this and I understand it pretty well, it doesn't help me if I don't know how to apply it in Starbound. Do I need a custom script just to get the movement working? At what point do I need to start using LUA? I know that I eventually will need a script, since I want collision with an entity to cause damage to the critter and I don't think you can so that with a JSON, but I don't know where to begin that or even what I need.
     
  7. The | Suit

    The | Suit Agent S. Forum Moderator

    Unless you learn the language - you won't be able to identify the mistakes.
    Once you learn it though - you will be able to decipher the code and what goes where by looking at all the associated files.

    Which are only 2 - 3 in the case of pets.
     

Share This Page