Forum rules - please read before posting.

Toggle-able menu item

edited August 2015 in Technical Q&A
A bit to do with another thread, where Im trying to get my character to hold stuff.

I need the method to do tis, but also some suggestions of the "methododgy" of my menu system.

In my game all items can be clicked on and are added to the inventory, SOME of them, NOT ALL you will use the normal Adventure Creator/Adventure game method. (Drag FROM the inventory TO the thing in the scene, like keys for example) but SOME things (gun and torch and axe) you should pick up (it goes to your inventory, but then when you click themin the inventory, they go to your hand.
When in your hand, pressing FIRE will.. er do them.. Torch =switch on or off Gun= fire, Axe = swing.
So then, with THOSE items, I need to be able to UN-equip them, I could have a key to do that, but thats a bit against my game interface (I want to keep things simple, without lots of different keys to remember)

To enter the Inventory at all (is 1st person game so you need to release the cursor) We hit TAB

So REALLY I need to be able to "put an item back" in the inventory, FROM your hand, I need the menu item to be a toggle button, one that STAYS selected, when you are holding it, and a second click will drop it. Of course, I also want it that if you go straight from holding the torch to holding the gun, it automatically drops the torch and takes the gun...

Is this waaay too tricky, or is there a better way to handle equipping, that isnt so far away from the Adventure game way of doing things?

Comments

  • Try using boolean Global Variables to keep track of what you're holding.  Selecting the torch in your inventory would check the value of e.g. "Holding torch?", and if False equips it (and sets it to True), otherwise unequips is (and sets it to False).
  • I had come to this conclusion actually, so just to "ice the cake" :) can the selected icon be made to stand while "holding" and off again when "not Holding"? Or is it a hard-coded "rollover" only?
  • Trying the variable thing... not working... First part is, (was working BEFORE I added the varaible) but second part (putting away the torch) isnt...

    Q: In the action list editor... should each action light up green as it fires? Even when its an Action List?
    Cos mine isnt... is that a hint?
  • Actions will only highlight in green while they run - so if it's an instantaneous Action (e.g. adding an inventory item), they won't get highlighted.  A better way of debugging an ActionList is to use the ActionList: Comment Action and use it to send messages to the Console.

    Perhaps a better way (and one that would also solve your "selected" item icon issue) would be to use the Inventory: Add or remove Action to swap your "unequipped" item with a separate "equipped" item with it's own icon.
  • edited August 2015
    What??? So you mean I make 2 inventory items? One for torch lit and one for torch.. unlit??
    Hmm.. thats interesting... never thought of that... you are a clever chap... If I remove one while adding another, will they occupy the same "slot" in the inventory... 
  • Hello Chris!
    Long time!
    Im STILL working on this... ok back after doing some paid jobs.
    Best ting is that I show you a flim.
    MANY issues at once here.
    First one is that although the concept of clicking an inventory item, the torch, and switching to an UNEQUIP menu item is working, the reference to the torch in the EQUIP is getting lost after first use of the torch. As is the references to the torch in the UNEQUIP action list.
    I am using Set parent/Clear parent to remove the torch, but to get rid of it I have to destroy it with remove object. Maybe cos its not destroyed it can't be found?

    Second LESSER issue is that the torch light, which is being turned on by the lightswitch script Message send Turn On.. is NOT turning off...
    EDIT: Sorry.. Last bit incorrect... when I shot the video I forgot to add the Torchlight to the light off (message send turn off) action in the UN-EQUIP inventory item... it MIGHT work now, but who knows as I cant get the torch to work a second time to find out... it might also be losing its reference.


  • First of all, make sure you are up-to-date on your AC version.

    The video's quite blurry to make out, but you don't need to re-drag your Torch asset into your Actions if the Actions show a recorded Constant ID number - as the Actions will search for any object with this number in the scene when the game runs.  But the Torch object itself needs to be in the scene when they run.

    If you're removing the object from the scene, you will have to make sure you also add the object when you need it.  You can use the Object: Check presence Action to determine whether-or-not the torch is in the scene, and add it in if not.

    Alternatively, just unparent the torch and hide it from view, instead of deleting it.
  • Ahh ok... (video shouldnt be blurry... but I do have a huge screen... I guess you need to stretch it out to correct size... generally looks crap in the Dropbox window)
    But seems like I may be deleting it for good...when I UN Equip it... I thought putting it in the hand again on EQUIP would add it back, but now I see that it IS in game from start... just sitting and waiting at 0,0,0... 
    how would YOU hide it from view? 
  • I'd just move it outside of the visible part of the game world.
  • Great.. thanks:
    One more thing.
    After clicking the torch inventory item, Id like to reset the cursor to center locked automatically without the user having to press that key again. How can I do this from an Action list?

    Mark
  • Im afraid this is beyond my rudimentary coding "skills". Followed the page you linked as far as duplicating the file, renaming the to things that caused the error, adding the title and description... and flomp... fell off...

    M
  • I'd still need to know the specifics to help.  How far did you get?
  • As I mentioned one post above... IE: nowhere... 
    If you are busy, then dont worry, RE: my other thread where Im hoping to NOT HAVE to lock the cursor to interact, depends on my Player movement...
    BUT.. Just to get the answer, if you are lazing around wondering what to do while the kettle boils../*
    *
    * Adventure Creator
    * by Chris Burton, 2013-2015
    *
    * "ActionTemplate.cs"
    *
    * This is a blank action template.
    *
    */

    using UnityEngine;
    using System.Collections;

    #if UNITY_EDITOR
    using UnityEditor;
    #endif

    namespace AC
    {

    [System.Serializable]
    public class ActionCursorLock : Action
    {

    // Declare variables here


    public ActionCursorLock ()
    {
    this.isDisplayed = true;
    category = ActionCategory.Custom;
    title = "CursorLock";
    description = "This should lock the cursor in center of the screen, fron an action list.";
    }


    override public float Run ()
    {
    /*
    * This function is called when the action is performed.
    *
    * The float to return is the time that the game
    * should wait before moving on to the next action.
    * Return 0f to make the action instantenous.
    *
    * For actions that take longer than one frame,
    * you can return "defaultPauseTime" to make the game
    * re-run this function a short time later. You can
    * use the isRunning boolean to check if the action is
    * being run for the first time, eg:
    */

    if (!isRunning)
    {
    isRunning = true;
    return defaultPauseTime;
    }
    else
    {
    isRunning = false;
    return 0f;
    }
    }


    #if UNITY_EDITOR

    override public void ShowGUI ()
    {
    // Action-specific Inspector GUI code here

    AfterRunningOption ();
    }


    public override string SetLabel ()
    {
    // Return a string used to describe the specific action's job.

    string labelAdd = "";
    return labelAdd;
    }

    #endif

    }

    }
  • The script's been renamed/declared correctly - you just have to place the right code in the Run function.  Since yours occurs instantly, it's very simple:

    override public float Run ()
    {
      AC.KickStarter.playerInput.cursorIsLocked = true;
      return 0f;
    }
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.