Forum rules - please read before posting.

Different types of hotpot?

Hi!

I need a special type of hotpot.
I already have a NPC Talk to type, that just shows the cursor and the name of the character, but now I need a hotspot that pops up a "info" graphic, like a small flag, when you hover over a variety of objects.
1. Can a hotspot display a diferent type of text box depending on what it is?
For example can hovering over a crate pop up a box that says "Crate with farm equipment" and a short sentance. Seems more like a menu to me?
2. As I have a lot of different objects to rollover, I wonder if I can use paramenters here (Not having used them before) so I make ONE menu "flag" and fill out different information per item?

thanks

Mark
«1

Comments

  • edited June 2015
    The difficulty here is that you want the menu to appear when you mouse-over, rather than click.  You won't be able to use parameters, because they'd be set in an Interaction (which gets run when you click).

    You can create a Menu with an Appear type set to On Hotspot, so that it will display when you mouse-over (no need to click).  Inside that menu, create a Label to store your info/description.

    This is the tricky part: you'll then have to write a custom Action that alters the description based on the Hotspot.  This, again, is necessary because this is to work with mouse-overs.  However, it should be quite simple.  Essentially, you want to attach a Constant ID number to your Hotspots (since this Action will be placed in an ActionList asset, so that it is scene-independent), and then have your Action read the "mouse over" Hotspot's ID and set the description accordingly.

    Something like this might go in your Action's Run function:
    string description = "";
    Hotspot activeHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
    if (activeHotspot != null && activeHotspot.GetComponent ())
    {
    int foundID = activeHotspot.GetComponent ().constantID;
      if (foundID == 123)
      {
        description = "Crate with farm equipment";
      }
      MenuElement myElement = PlayerMenus.GetElementWithName ("InfoMenu", "InfoLabel");
      MenuLabel myLabel = (MenuLabel) myElement;
      myLabel.label = description;
    }
    (Where "InfoMenu" and "InfoLabel" are the names of your menu/label respectively, and 123 is an example ConstantID number).  More on custom Actions can be found here, as well as in the manual.  You'd then place this Action inside an ActionList that's set to run when your Menu turns on.
  • Thats absolutely fab!
    I have one more question, because I did find the Appear Type, and tried setting it to On Hotspot. and yes it DID work as I wanted. However, it would pop up for every hotspot, including NPCs in additin to the previously defined "Hotspot" menu.

    Will your script, due to the constant ID and the dynamic labels the script provide effectively weed out these "normal" Hotspot" labels?

    Ive never done any custome actions before, is this (above) the whole thing? Or just aprt of an actin (I mention cos you said "in your Action's Run function" which suggests to me its an excerpt)

    Well Ill go and watch the link.. maybe I get the answer tehre..
    Thanks again...
  • If you keep things simple, you shouldn't need anything in the other functions, since that's more for when you want GUI controls on your Action.  But yeah, that's the general gist of it.  You should be able to add something at the end that turns the menu off if there's nothing to show, e.g:

    if (found == 123)
    {
     // do something
    }
    else
    {
      PlayerMenus.GetMenuWithName ("InfoName").TurnOff (true);
    }
  • Hi, 

    Im just getting round to actually doing this now, A few question.
    Please bare in mind that I am not a coder :)
    First, in the ActionTemplate.cs file (currently re-named to ActionHotspotPopUp.cs - including the class name and constructor, so no more console error)
    ... do I replace the commented out (grey) section of the run function, or the whole damn thing? Including the...
    if (!isRunning)
                {
                    isRunning = true;
                    return defaultPauseTime;
                }
                else
                {
                    isRunning = false;
                    return 0f;
                }

    Or IS THAT the bit you suggest replaceing with the if (found ==123) snippet above?

    To be honest I dont quite understand what you mean that bit to do. "ou should be able to add something at the end that turns the menu off if there's nothing to show" ... doesnt the menu turn off by default, its on rollover right?, so roll off = no menu?

    Also, how are both these scripts going to "find" the constant ID (the 123 in the scripts). Do I have to add the constant ID to the menu then whatevr adventure creator gives it as an ID, I thin come into this code and "hard-code" it in?
    Thats fine, just need to know...

    Ill be trying this now anyway, so I may "stumble upon" the answer anyway...

    Thanks for all your help... Hope you notice that my posts are becoming slightly less frequent? This is a good thing!
    :)

    Mark  

  • Ran out of editting time.. See above: Now I actually READ the comment in ActionTemplate, so that code was for checking to see if it had been run before, so I guess I DONT need it.

    Other questions still relevant
  • edited June 2015
    OK
    Sorry, Im sure this is NON-programmer problems, and its not your job to teach me to code, but insterting the above thru a bunch of errors
    Heres the complete code as I have it now.
      override public float Run ()
    {
    /* MArk Code!!!
    */
    string description = "";
    Hotspot activeHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
    if (activeHotspot != null && activeHotspot.GetComponent ())
    {
    int foundID = activeHotspot.GetComponent ().constantID;
    if (foundID == 123)
    {
    description = "Crate with farm equipment";
    }
    MenuElement myElement = PlayerMenus.GetElementWithName ("InfoMenu", "InfoLabel");
    MenuLabel myLabel = (MenuLabel) myElement;
    myLabel.label = description;
    }
    /*
    * 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;
    }
    */
    }

    You cant see it too clearly here (without being in monodevelop) but I commented out the code snippet, and this removed another error

    And here are the errors

    Assets/MyCustomActions/ActionHotspotPopUp.cs(44,55): error CS1026: Unexpected symbol `;', expecting `)'
    Assets/MyCustomActions/ActionHotspotPopUp.cs(44,60): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
    Assets/MyCustomActions/ActionHotspotPopUp.cs(44,103): error CS1525: Unexpected symbol `)', expecting `;'
    Assets/MyCustomActions/ActionHotspotPopUp.cs(85,38): error CS0116: A namespace can only contain types and namespace declarations
    Assets/MyCustomActions/ActionHotspotPopUp.cs(93,40): error CS0116: A namespace can only contain types and namespace declarations
    Assets/MyCustomActions/ActionHotspotPopUp.cs(105,1): error CS8025: Parsing error
  • The errors don't mean much without knowing the line numbers - what's on line 44?

    You're correct to comment out the whole block of code that was already within Run () (in fact you're better off deleting it), but you need to replace it with a zero float return.  End the function with:

    return 0f;
  • edited June 2015
    Heres the code:
    Doing it again meant that this time (deleting rather than commentin) gave slightly different line numbers:
    Assets/MyCustomActions/ActionHotspotPopUp.cs(42,55): error CS1026: Unexpected symbol `;', expecting `)'
    Assets/MyCustomActions/ActionHotspotPopUp.cs(42,60): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
    Assets/MyCustomActions/ActionHotspotPopUp.cs(42,103): error CS1525: Unexpected symbol `)', expecting `;'
    Assets/MyCustomActions/ActionHotspotPopUp.cs(59,38): error CS0116: A namespace can only contain types and namespace declarations
    Assets/MyCustomActions/ActionHotspotPopUp.cs(67,40): error CS0116: A namespace can only contain types and namespace declarations
    Assets/MyCustomActions/ActionHotspotPopUp.cs(79,1): error CS8025: Parsing error
    image
  • Seems it's my fault.  The forum reformatted my code when I pasted it: the "&" signs on 42 shouldn't have "amp;" after them.
  • Ahh.. cool... ill go back to checking that out..

    in the meantime... player broken.. no cursor moving... mark sad...  head hurts...see new thread...

  • Hi, nearly there now.. :)

    OK I removed the amps and so I still get one error:

    Assets/MyCustomActions/ActionHotspotPopUp.cs(38,39): error CS0161: `AC.ActionHotspotPopUp.Run()': not all code paths return a value

    To avoid the forum re-writing, heres an image... I also had one small query about the naming of the "class name and constructor" as mentioned in the tutorial (http://www.adventurecreator.org/tutorials/writing-custom-action)
    Are there included in your code snippet, and should they be the same name? Ive written on the image to explain..

    image
  • UPDATE!
    OK I fixed the error, After your return 0f; point I had added it one line to early, and I get what that does now... If.. blah blah blah then do blah blah blah but ... if not... then return 0, or do nothing..

    But now on running my scene (before tying to actually implementing that script anywhere, I get

    Loading script assembly "Library/ScriptAssemblies/Assembly-UnityScript.dll" failed!


  • That's a problem with Unity, rather than AC.  Temporarily remove your custom action from the project, and see if things are solved.  You might have to create a new script file and paste the code in again, if so.  Otherwise, you'll have to search the Unity forums for something - again, this is not an issue with AC, and I can't advise.
  • Im sorry to keep bashing away at this but..

    1. Thanks for the suggestion of re-making the file, that seemed to work.
    2. however when try to implement it...
    you said above:
    You'd then place this Action inside an ActionList that's set to run when your Menu turns on.
    Then I realised that I didnt know where to find this action, if its working, wouldnt it appear in the drop down menu for Action Type...
    Checking the "Actions" Tab in the editor I realised that your instructions to put this is a MyCustomActions foder are not completely complete, as I need to set the location of the customs actions folder, so I did.. then this appeared..

    Instance of ActionHotspotPopUp couldn't be created. The the script class needs to derive from ScriptableObject.
    UnityEngine.ScriptableObject:CreateInstance(String)
    AdventureCreator:RefreshActions() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:426)
    ActionListAssetEditor:OnEnable() (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListAssetEditor.cs:25)

  • edited June 2015
    And the script is exactly as it was in your last screenshot, barring the mis-placed "return 0f;"?  The line references in the error don't match up with the latest - update to the latest version of AC, and re-post the error if it persists.

    The placement in the editor will depend on your category and title fields - you've currently got this as Category.Custom and "Template" (the default values), which will mean the Action is listed as Custom: Template.
  • edited July 2015
    Hi
    Yeah it could be that I had tried a few things and the lines got messed up, sorry.. Here it is all new..
    And yes.. latest AC installed. (Not latest Unity tho, Ive been holding off U5 for a bit, I scared it will break a few projects Im working on, so want to be done with a couple, or at least at a no error state.)

    Heres the current error:

    Instance of ActionHotspotPopUp couldn't be created. The the script class needs to derive from ScriptableObject.
    UnityEngine.ScriptableObject:CreateInstance(String)
    AC.AdventureCreator:RefreshActions() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:428)
    AC.AdventureCreator:OnGUI() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:285)
    UnityEditor.DockArea:OnGUI()

    and the script that causes it:

    image


  • edited July 2015
    It all looks fine to me - I'm assuming you haven't changed any of AC's core files.  Is there another class / script with the same name (ActionHotspotPopUp)?  If there's a backup or something somewhere else in your Assets folder, that might cause problems.

    If not, try replacing "Action" on line 23 with "AC.Action".  The only other thing I can think of is that there's another class called Action in your project that Unity's getting confused with.
  • Strange, all seems ok now...at least no errors... a restart of Unity clear something out...
    Now to figure out how you meant me to use it... ha ha
    If I understand correctly, this action goes on the menu "Action list when turn on"
    and a constant ID componant is added to all my objects, then...

    ...Well Ill get that far and see what happens...

    M


  • edited July 2015
    I said
    ...Well Ill get that far and see what happens...

    Not too far as it happens :(

    Thing is Im not completely understanding your idea here.
    Above I took it to mean that the MENU InfoMenu would contain this action on the action list when turn on slot.
    But then, where do I actually add the separate descriptions for all the items? I get that there should be space for the text and the constant ID number (Are there public variables I need to add?) But even so, If the script is added at that level, then I would only get that instance of the actin to add one description?

    I do hope you didn't misunderstand my needs?

    Thing is, that I want a different text to pop up on rollover on all these separate objects.
    Now If your idea was to add the action to each hotspot,then I would understand, cos then each hotspot would sent its description text to the menu, that would populate when rolled over.

    Am I missing something obvious here?

    and thanks again for your continued patience...

    MArk





  • What I suggested still matches what you've explained here - you should indeed place it in your "ActionList when turn on" field.

    The sample code is an example: it checks if the Constant ID number on the current Hotspot is 123, and sets the description label if it is.  You'd have to change that number, and add other "if" clauses to check for other Hotspots - no need to add any more public variables.
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.