Forum rules - please read before posting.

action as long as key is pressed

As long as I press a key (that I specify in InputManager) an Action is executed and  stays until I release  it and it goes back the way it was before. In short  to 'momentarily' turn something on with a key and hold it until I release it.


Comments

  • The Input: Check Action can be used to determine if a button is held down or not, but if you want to detect the moment it's pressed and released, you'll want to run a custom script that checks for Input.GetButtonDown and Input.GetButtonUp in it's Update script.  You can then run an ActionList from within the script by calling its Interact function directly.
  • I created the script you mention and place it inside an empty Object ,then I make an Object:SendMessage,

    Object to affect: my EmptyObject,

     Message to send: Custom,

    Method name: Update

    But when I useplace the Interact function ACActionList.Interaction() it says I need an (int,bool) ???



    void Update( )

        {

            if (Input.GetKeyDown (KeyCode.Space)) {

                Debug.Log ("Space key was pressed.");

                AC.ActionList.Interact (); ?????????????????

            }

            if( Input.GetKeyUp( KeyCode.Space ) )

                Debug.Log( "Space key was released." );

        }

    I am at a loss as far as the flow of these, I would appreciate help

  • The Update function will be called every frame by Unity - you don't want or need to call it directly with Object: Send message.

    As for Interact, you need to call the function from an instance of the ActionList class - not the ActionList class itself.  This isn't a programming forum or a guide for coding in Unity, but basically:

    // Put this outside the Update() function
    public AC.ActionList myActionList;

    // Replace your current Interact call with:
    myActionList.Interact ();


    You'll then see "My Action List" appear in the Inspector for you to assign.
  • I have done it another way by clicking the special key once to do it and again to undo it since I still don't understand your solution.

    Incidentally, AC. functions like AC.ActionList and others of that kind do not exist in Unity itself but  is a byproduct of Adventure Creator therefore I asked this Forum instead of Unity's

  • edited October 2016
    I can understand your confusion, I only started learning programming like 5 months ago, so the first time I saw AC's API, like 2 or 3 months ago, it felt very confusing at first. But the thing is the phrasing of the code lines in the API is set up to let other programmers know the classes and types, and also the overall construction/organization of the methods. What this means is that what's written there isn't always exactly how you use the code in practice... for example, as Chris mentioned, In many cases you have to replace the class name with an actual instance of an object (or in other words you have to make a variable of that class type and assign it an object, like in the example above). This are general programming conventions which most seasoned programmers understand immediately nowadays... Though I can't say I'm one of them yet, lol, I still get confused in some cases too.. but anyway, unfortunately most APIs (in any asset or software) aren't very noob friendly... That's something I had to learn the hard way, lol.

    Anyway, as far as I noticed you get an error in your code above because AC has another method almost identical, but which is intended to be used slightly differently, which is trying to execute instead because you are skipping the instance (and that other code needs parameters). What Chris meant you to do is this:

    public AC.ActionList myActionList;
    void Update( )
        {
            if (Input.GetKeyDown (KeyCode.Space)) {

                Debug.Log ("Space key was pressed.");

                myActionList.Interact ();
            }

            if( Input.GetKeyUp( KeyCode.Space ) )

                Debug.Log( "Space key was released." );
        }

    Once this is done you can give the script to any object and use Unity's drag and drop functionality to drop any actionlist asset into that object's inspector tab. And with this method there's no need to use Object:Send message actions.
  • First, thank you.

     I don't have any script errors any more however I am unable to drag any actionList asset in the inspector. Here is what the Inspector shows

    -------------------------------------------------

    ToggleKey (an empty GameObject

    ToggleSwitch (script)

    My Action List:      None (Action List)

    ----------------------------------------------

    and I can't drag any of my 20 something ActionList Assets into the My Action List however  it accepts  Cutscenes assets, so I copied the contents of my ActionList into a Cutscene and then it works.

    Try it if you want, why does it accept Cutscenes and not ActionList ? I personally don't care as long as the results are OK.







  • An ActionList asset has the class name ActionListAsset.  If you want to be able to place in assets, and not Cutscenes, replace "ActionList" in your code with "ActionListAsset".
  • Got it, thanks
  • wow, sorry... when I was editing the code I didn't notice I wasn't using the asset version, I just assumed. Anyway, it's good to know you got it working :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.