Modding Help .lua code: Trying to work out how to reset an objects animation

Discussion in 'Starbound Modding' started by Pinchy, Dec 16, 2013.

  1. Pinchy

    Pinchy Subatomic Cosmonaut

    In my current lua code:

    function main()
    -- Check for the single execution
    if self.initialized == nil then
    -- Init object
    initializeObject();
    -- Set flag
    self.initialized = true;
    end
    end

    function initializeObject()
    -- Set animation as "active"

    object.setInteractive(true);
    object.setAnimationState("beaconState", "active");

    end

    function onInteraction(args)
    -- Change animation to "skree"

    object.setAnimationState("beaconState", "skree");
    object.playSound("skreeSounds");
    end

    So I can place the object, when it is interacted with it plays "beaconState", "skree", however it just stops on the last frame of that animation and does not loop back to "beaconState", "active"
     
  2. Pinchy

    Pinchy Subatomic Cosmonaut

    This is the last step in finishing this object mod.

    There might be something outside of the .lua that has to be added to but I don't know what.

    Surely there would be some simple code to return to a previous animation that is set to loop ("active")
     
  3. Nightmares

    Nightmares Scruffy Nerf-Herder

    Is your goal to have the animation loop?
     
  4. Nightmares

    Nightmares Scruffy Nerf-Herder

    I don't know why but I read everything but your very last sentence. I've noticed in some of the animation jsons there's a field that goes under frames and cycle called "mode" and can have a value of loop
    Code:
              "walk" : {
                "frames" : 8,
                "cycle" : 1.0,
                "mode" : "loop"
              },
     
  5. Pinchy

    Pinchy Subatomic Cosmonaut

    I thought there might be a field that has something like:

    "playcount" : "3"

    but I don't know where to look that up.


    The current setup is:

    Place object, it loops "active"

    Interact with object, it plays "skree" (but then stops)


    I want it to return to "active"
     
  6. Nightmares

    Nightmares Scruffy Nerf-Herder

    re-initialize before you end your onInteraction method:

    Code:
    function onInteraction(args)
    -- Change animation to "skree"
    object.setAnimationState("beaconState", "skree");
    object.playSound("skreeSounds");
    initializeObject();
    end

    is "skree" like a pig squeal? not important, just curious
     
  7. Pinchy

    Pinchy Subatomic Cosmonaut

    When I set the code like that, it plays the sound completely but the "skree" state animation instantly ends (doesn't even play)

    Also, is there a way to make the object have a speech bubble above it with a message like players?

    I tried using the say and emote but they did nothing:

    object.say("Message");

    and

    object.emote("Message");

    Sounds are played using:

    object.playSound("skreeSounds");

    with this in the .object file:


    "skreeSounds" : [ "/assets/sfx/objects/skrees.wav" ]

    So would messages be created using:

    object.say("skreeMessage");
    or object.emote("skreeMessage");

    with this in the .object file:

    "skreeMessage" : [ "not sure what goes here" ]
     
  8. Nightmares

    Nightmares Scruffy Nerf-Herder

    The reason the skree animation ends right away is because there's no timer or something to tell you that it's not finished playing yet and the next function is called right away. See if the play animation function returns a boolean, then maybe you could do a while or if statement.

    As for the messages, I've noticed the merchants use a function called "sayToTarget()". I don't know if this only works for merchants or npcs though. Check out the .npctypes and then check out the merchantState.lua and see if that helps you any.
     
  9. Pinchy

    Pinchy Subatomic Cosmonaut

    This is the function in \assets\npcs\merchant\merchantState.lua:

    function merchantState.enteringState(stateData)
    sayToTarget("merchant.dialog.start", stateData.sourceId)
    end


    This is the function in \assets\npcs\merchant\merchant.npctype:

    "scriptDelta" : 5,
    "scriptConfig" : {
    "idleTimeRange" : [2.0, 10.0],

    "merchant" : {
    "waitTime" : 10,
    "storeRadius" : 8,

    "dialog" : {
    "start" : {
    "default" : [
    "Welcome to my shop.",
    "See anything you like?",
    "What can I do ya for?"
    ],

    }


    These things are beyond my understanding right now so I will have to wait until someone makes an object that does similar things and look at the code.
     
    Last edited: Dec 17, 2013
  10. Nightmares

    Nightmares Scruffy Nerf-Herder

    You see how the lua specifies the state as entering? This means entering negotiation in this instance. So in sayToTarget he finds merchant-> goes to the dialog branch -> goes to the start branch -> chooses one of the pre-designated things to say based on the second parameter which is the sourceId.

    If you look at one of these branches:
    Code:
         
     "dialog" : {
            "end" : {
                "glitch" : {
                    "default" : [
                        "Content. Please come again.",
                        "Pleased. Thank you for your patronage.",
                        "Disappointed. You're not going to buy more?",
                        "Melancholy. Until next time, customer."
                        ]
                    },
    
    Glitch would mean the vendor is of glitch type, and the following default is what the glitch would say if it can't determine what the other subject is.
    You can very well hardcode all this to suit your very own race's needs ie. sayToTarget("That bitch stole my wallet", "avian").
     
  11. Pinchy

    Pinchy Subatomic Cosmonaut

    I tried a few combinations, if I put the sayToTarget line before the playSound, the sounds don't play.

    In my .lua:

    function onInteraction(args)
    object.setAnimationState("beaconState", "skree")
    object.playSound("skreeSounds");
    sayToTarget("skreeDialog", stateData.sourceId);
    end


    In my .object:

    "skreeDialog" : {
    "default" : [
    "Message"
    ]
    }

    Do i need to add .default after .skreeDialog so it's skreeDialog.default or does it read from that anyway.


    From the log:



    Error: Exception while invoking lua method 'onInteraction'. LuaException: [string "/assets/objects/wired/skree/skree..."]:22: attempt to index global 'stateData' (a nil value)
     
  12. Nightmares

    Nightmares Scruffy Nerf-Herder

    Ok, what's happening is you're not setting sourceId to anything and you're trying to index through a tree that you don't have yet. If you're going to use their hierarchy (and I suggest you do), you're going to need another array inside default (which, yes should be skreeDialog.default) that should also be called default and another in that that should be called default and have your dialogs in there.

    To fix the stateData.sourceId problem (in case you want to do that personalized race thing) try putting at the very top of that function sourceId = args.interactArgs.sourceId and pass the function sourceId and not stateData.sourceId (since stateData doesn't exist in this function)
     
  13. Nightmares

    Nightmares Scruffy Nerf-Herder

    The sounds dont play because you forgot a semi-colon at the end of the object.setAnimationState("beaconState", "skree") line
     
  14. Pinchy

    Pinchy Subatomic Cosmonaut

    It was only missing from the post, checked it and tried again same thing.

    I deleted the commented out line above that one to make it easier to read and took that with it by mistake.
     
  15. Nightmares

    Nightmares Scruffy Nerf-Herder

    Put sayToTarget first then, just like the reinitialize was cutting off the animation the sayToTarget is cutting off the sound
     
  16. Nightmares

    Nightmares Scruffy Nerf-Herder

    return { "ShowPopup", { message = "No signal! Please activate on planet surface." } }
     

Share This Page