Forum rules - please read before posting.

Button simulating input with action list?

edited November 2017 in Technical Q&A
Hey guys,
I need a button on screen to simulate pressing the 0 button when clicked while activating an action list at the same time. 
Do you have any idea how to do this?
I know you can simulate input by using the "simulate input" menu click type but I can't think of a way to make it run an actionlist after.

Thank you :)

Comments

  • The menu button can be used to simulate input, but you still need to tell AC to detect such input - regardless of whether its simulated or real.

    This is done using "Active Inputs" - see Section 2.6 of the Manual.  Be aware that the "Input name" you set must be the name of the input as listed in your Unity Input Manager, not the name of the key that must be pressed.
  • Hey Chris, thank you I've done this but the game isn't picking it up.

    The custom javascript script I have running on my sound prefab will only run if the button 0 is pressed. So when you click a certain menu button, it's supposed to simulate the 0 button being pressed and run the script. It's in javascript, is that a problem?

    I have 0 as an active input, 0 in my input manager and made sure both the input name and button is '0', and the menu button has simulated input 0. 
    What have I done wrong?
  • edited November 2017
    Without seeing the code I can't really comment on it, but you should always rely on C# instead of JS when you want to communicate with AC, as that is what AC is written in.  However, AC is already equipped to detect input and simulate it when a menu button is pressed.

    Ignoring the custom code / simulation for the moment, focus on just getting the Active Input to work.  You can quickly determine if the ActionList is run by adding an ActionList: Comment Action to it so that a log can be printed to the Console when run.

    Once the Active Input runs when pressing the "0" key on your keyboard ("[0]" is required for the keypad, see this page), then we can focus on having it simulated.
  • Hey Chris, the game is running the comment in the actionlist so I have the active input working now. Now having the button 0 simulated is the problem....
  • Let's see what your Menu Button's properties look like.  Know that the Active Input's Available when game is field will have to match up with the state of the game when the Menu in question is open.

    For example, if the Menu pauses the game, the Active Input will have to be set up to respond when the game is paused.

    You can test this out quickly by creating a new Active Input that works when the game is "Normal", and changing the default InGame Menu's MenuButton to have a Click type of Simulate Input, and entering in the name of the Unity input axis into the field that then appears.
  • edited November 2017
    Hi Chris,
    I set the InGame button "MenuButton" simulate input key to 0, and when clicking on it it runs the active input action list, but the JS script in the background which is supposed to activate upon key press of 0 still isn't activated. It only works if I press 0 manually. 
    Here's a bunch of images that I hope will help (relating to my own button not the default ingame one)

    If it helps, there's 9 JS scripts and 9 sound objects, there's 1 script for each sound object and when 0 is pressed, then a script runs that writes the sound from the sound objects to a .wav file. It works if I press 0 on my own, both the actionlist and all JS scripts are run like it should do, but trying to get AC to simulate pressing 0 runs the action list that lets the player know it's recording, but the JS scripts don't run.
  • There's no mention in these screens of your JS scripts - I'm assuming they're referenced in the "pianorecord" ActionList?

    Again you should be using C# if you want to use scripts in conjunction with AC.  You say the AC side of things is working in that the Active Input and the simulated button both work, so it sounds like the issue lies instead with your own scripts.  How are you calling those scripts in the pianorecord ActionList?  With an Object: Send message Action?
  • Hi Chris,
    There's 9 JS scripts and each one is on the corresponding sound object (audiorecord1.JS on default sound 1 for example)
    So I don't think I can run it from a Call Event or Send Message or it won't pick up any sound as it needs to be run from the sound object.
  • You haven't posted the code, but if it's not working with AC's Actions then you'd need to rewrite it in C#.  Adapting from one to the other isn't generally that tricky - how complex are the scripts?
  • Hey Chris,
    I don't think it's complex, but admittedly I don't have much experience with C# which is why I haven't converted JS to it yet... I apologize for how stressy this thread must be.

    I can't find a 'show/hide code' button on here so would it be easier if I just uploaded it? Here it is
  • Hey admiralalamott,

    I'll jump in to help a bit and transfer your JS script to C#. Make a new C# script called TestScript and paste this in it:

    Here
  • Heya
    Thanks Kole for that, I've replaced the scripts on the sound object with yours and they work fine if I press 0...but yet again I still can't simulate the button 0 haha :))
    The scripts aren't called by an actionlist, they're put in the sound objects and the "get key down" is under update() which keeps it checking constantly. 
    Perhaps something needs to be put in the script to work with AC?
  • edited November 2017
    I don't think you've understood the purpose of AC's simulating features here.  It won't simulate Unity's raw inputs, but instead AC's own internal input detection.

    You don't need a script to read Unity.GetKeyDown - that's what Active Inputs do for you!  At the moment, you're doing both - so there's no way to know if the code is running because it's from your own script, or due to the input.

    You need to include a public  function in your script that the Active Input's ActionList invokes.  It will then be available to select when using the Object: Call event Action.

    Remove the Input.GetKeyDown code in a new test script, and again go back to just having the Active Input invoke it - you can place a Debug.Log statement in the public function to confirm that AC is running it.  Only once that is working, you should go about having it work with a simulated button.
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.