Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EntropicJoey · Apr 14, 2012 at 01:07 PM · cs

broadcasting error for targetting script

I APOLOGIZE TRULY, after seeing the scripts all layed out on here like this i saw the problem very quickly lol, i labled "show mob vitals bars" without a space in the vital script, so the fix would be spacing this out in the vitalbars.cs script or by removing the spaces in this first script, again sorry for the wasted space lol

BroadcastException: Broadcasting message show mob vital bars but no listener found. MessengerInternal.OnBroadcasting (System.String eventType, MessengerMode mode) (at Assets/_Scripts/_Messenger/Messenger.cs:64) Messenger`1[System.Boolean].Broadcast (System.String eventType, Boolean arg1, MessengerMode mode) (at Assets/_Scripts/_Messenger/Messenger.cs:139) Messenger`1[System.Boolean].Broadcast (System.String eventType, Boolean arg1) (at Assets/_Scripts/_Messenger/Messenger.cs:135) Targeting.DeselectTarget () (at Assets/_Scripts/_Player/Targeting.cs:87) Targeting.TargetEnemy () (at Assets/_Scripts/_Player/Targeting.cs:63) Targeting.Update () (at Assets/_Scripts/_Player/Targeting.cs:93) ive searched endlessly and i cannot solve this problem, any help would be a god send lol

heres the code

 ///  this script canbe attached to any permanent gameobject. and is responsible for allowing the player to target different mobs that are within range
 /// </summary>
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Targeting : MonoBehaviour {
     public List<Transform> targets;
     public Transform selectedTarget;
     
     private Transform myTransform;
         
     // Use this for initialization
     void Start () {
     targets = new List<Transform>();
         selectedTarget = null;
         myTransform = transform;
         
         AddAllEnemies();
     }
     
     public void AddAllEnemies()
     {
         GameObject[] go = GameObject.FindGameObjectsWithTag("Enemy");
         
         foreach(GameObject enemy in go)
             AddTarget(enemy.transform);
     }
     
     public void AddTarget(Transform enemy)
     {
         targets.Add (enemy);
     }
     private void SortTargetsByDistance()
     {
         targets.Sort(delegate(Transform t1, Transform t2) {
             return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position));
         });
   }
     private void TargetEnemy()
     {
         if(selectedTarget == null)
         {
             SortTargetsByDistance();
             selectedTarget = targets[0];
         }
         else
         {
             int index = targets.IndexOf(selectedTarget);
             
             if(index < targets.Count - 1)
             {
                 index++;
             }
             else
             {
                 index = 0;
             }
             DeselectTarget();
             selectedTarget = targets[index];
 
         }
                     SelectTarget();
     }
     
     private void SelectTarget() {
         Transform name = selectedTarget.FindChild("Name");
         
         if(name == null) {
         Debug.LogError("Could not find the name on " + selectedTarget.name);
             return;
         }
         
         name.GetComponent<TextMesh>().text = selectedTarget.GetComponent<Mob>().Name;
         name.GetComponent<MeshRenderer>().enabled = true;
          selectedTarget.GetComponent<Mob>().DisplayHealth();
         
         Messenger<bool>.Broadcast("show mob vital bars", true);
     }
     private void DeselectTarget() {
         selectedTarget.FindChild("Name").GetComponent<MeshRenderer>().enabled = false;
         selectedTarget = null;
         Messenger<bool>.Broadcast("show mob vital bars", false);
     }
     
     // Update is called once per frame
     void Update () {
     if(Input.GetKeyDown(KeyCode.Tab)) {
             TargetEnemy();
         }
     }
 }



oh and here is messenger.cs sorry / Messenger.cs v1.0 by Magnus Wolffelt, magnus.wolffelt@gmail.com // // Inspired by and based on Rod Hyde's Messenger: // http://www.unifycommunity.com/wiki/index.php?title=CSharpMessenger // // This is a C# messenger (notification center). It uses delegates // and generics to provide type-checked messaging between event producers and // event consumers, without the need for producers or consumers to be aware of // each other. The major improvement from Hyde's implementation is that // there is more extensive error detection, preventing silent bugs. // // Usage example: // Messenger.AddListener("myEvent", MyEventHandler); // ... // Messenger.Broadcast("myEvent", 1.0f);

 using System;
 using System.Collections.Generic;
 
 public enum MessengerMode {
     DONT_REQUIRE_LISTENER,
     REQUIRE_LISTENER,
 }
 
 
 static internal class MessengerInternal {
     static public Dictionary<string, Delegate> eventTable = new Dictionary<string, Delegate>();
     static public readonly MessengerMode DEFAULT_MODE = MessengerMode.REQUIRE_LISTENER;
 
     static public void OnListenerAdding(string eventType, Delegate listenerBeingAdded) {
         if (!eventTable.ContainsKey(eventType)) {
             eventTable.Add(eventType, null);
         }
 
         Delegate d = eventTable[eventType];
         if (d != null && d.GetType() != listenerBeingAdded.GetType()) {
             throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
         }
     }
 
     static public void OnListenerRemoving(string eventType, Delegate listenerBeingRemoved) {
         if (eventTable.ContainsKey(eventType)) {
             Delegate d = eventTable[eventType];
 
             if (d == null) {
                 throw new ListenerException(string.Format("Attempting to remove listener with for event type {0} but current listener is null.", eventType));
             } else if (d.GetType() != listenerBeingRemoved.GetType()) {
                 throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
             }
         } else {
             throw new ListenerException(string.Format("Attempting to remove listener for type {0} but Messenger doesn't know about this event type.", eventType));
         }
     }
 
     static public void OnListenerRemoved(string eventType) {
         if (eventTable[eventType] == null) {
             eventTable.Remove(eventType);
         }
     }
 
     static public void OnBroadcasting(string eventType, MessengerMode mode) {
         if (mode == MessengerMode.REQUIRE_LISTENER && !eventTable.ContainsKey(eventType)) {
             throw new MessengerInternal.BroadcastException(string.Format("Broadcasting message {0} but no listener found.", eventType));
         }
     }
 
     static public BroadcastException CreateBroadcastSignatureException(string eventType) {
         return new BroadcastException(string.Format("Broadcasting message {0} but listeners have a different signature than the broadcaster.", eventType));
     }
 
     public class BroadcastException : Exception {
         public BroadcastException(string msg)
             : base(msg) {
         }
     }
 
     public class ListenerException : Exception {
         public ListenerException(string msg)
             : base(msg) {
         }
     }
 }
 
 
 // No parameters
 static public class Messenger {
     private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
 
     static public void AddListener(string eventType, Callback handler) {
         MessengerInternal.OnListenerAdding(eventType, handler);
         eventTable[eventType] = (Callback)eventTable[eventType] + handler;
     }
 
     static public void RemoveListener(string eventType, Callback handler) {
         MessengerInternal.OnListenerRemoving(eventType, handler);   
         eventTable[eventType] = (Callback)eventTable[eventType] - handler;
         MessengerInternal.OnListenerRemoved(eventType);
     }
 
     static public void Broadcast(string eventType) {
         Broadcast(eventType, MessengerInternal.DEFAULT_MODE);
     }
 
     static public void Broadcast(string eventType, MessengerMode mode) {
         MessengerInternal.OnBroadcasting(eventType, mode);
         Delegate d;
         if (eventTable.TryGetValue(eventType, out d)) {
             Callback callback = d as Callback;
             if (callback != null) {
                 callback();
             } else {
                 throw MessengerInternal.CreateBroadcastSignatureException(eventType);
             }
         }
     }
 }
 
 // One parameter
 static public class Messenger<T> {
     private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
 
     static public void AddListener(string eventType, Callback<T> handler) {
         MessengerInternal.OnListenerAdding(eventType, handler);
         eventTable[eventType] = (Callback<T>)eventTable[eventType] + handler;
     }
 
     static public void RemoveListener(string eventType, Callback<T> handler) {
         MessengerInternal.OnListenerRemoving(eventType, handler);
         eventTable[eventType] = (Callback<T>)eventTable[eventType] - handler;
         MessengerInternal.OnListenerRemoved(eventType);
     }
 
     static public void Broadcast(string eventType, T arg1) {
         Broadcast(eventType, arg1, MessengerInternal.DEFAULT_MODE);
     }
 
     static public void Broadcast(string eventType, T arg1, MessengerMode mode) {
         MessengerInternal.OnBroadcasting(eventType, mode);
         Delegate d;
         if (eventTable.TryGetValue(eventType, out d)) {
             Callback<T> callback = d as Callback<T>;
             if (callback != null) {
                 callback(arg1);
             } else {
                 throw MessengerInternal.CreateBroadcastSignatureException(eventType);
             }
         }
     }
 }
 
 
 // Two parameters
 static public class Messenger<T, U> {
     private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
 
     static public void AddListener(string eventType, Callback<T, U> handler) {
         MessengerInternal.OnListenerAdding(eventType, handler);
         eventTable[eventType] = (Callback<T, U>)eventTable[eventType] + handler;
     }
 
     static public void RemoveListener(string eventType, Callback<T, U> handler) {
         MessengerInternal.OnListenerRemoving(eventType, handler);
         eventTable[eventType] = (Callback<T, U>)eventTable[eventType] - handler;
         MessengerInternal.OnListenerRemoved(eventType);
     }
 
     static public void Broadcast(string eventType, T arg1, U arg2) {
         Broadcast(eventType, arg1, arg2, MessengerInternal.DEFAULT_MODE);
     }
 
     static public void Broadcast(string eventType, T arg1, U arg2, MessengerMode mode) {
         MessengerInternal.OnBroadcasting(eventType, mode);
         Delegate d;
         if (eventTable.TryGetValue(eventType, out d)) {
             Callback<T, U> callback = d as Callback<T, U>;
             if (callback != null) {
                 callback(arg1, arg2);
             } else {
                 throw MessengerInternal.CreateBroadcastSignatureException(eventType);
             }
         }
     }
 }
 
 
 // Three parameters
 static public class Messenger<T, U, V> {
     private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
 
     static public void AddListener(string eventType, Callback<T, U, V> handler) {
         MessengerInternal.OnListenerAdding(eventType, handler);
         eventTable[eventType] = (Callback<T, U, V>)eventTable[eventType] + handler;
     }
 
     static public void RemoveListener(string eventType, Callback<T, U, V> handler) {
         MessengerInternal.OnListenerRemoving(eventType, handler);
         eventTable[eventType] = (Callback<T, U, V>)eventTable[eventType] - handler;
         MessengerInternal.OnListenerRemoved(eventType);
     }
 
     static public void Broadcast(string eventType, T arg1, U arg2, V arg3) {
         Broadcast(eventType, arg1, arg2, arg3, MessengerInternal.DEFAULT_MODE);
     }
 
     static public void Broadcast(string eventType, T arg1, U arg2, V arg3, MessengerMode mode) {
         MessengerInternal.OnBroadcasting(eventType, mode);
         Delegate d;
         if (eventTable.TryGetValue(eventType, out d)) {
             Callback<T, U, V> callback = d as Callback<T, U, V>;
             if (callback != null) {
                 callback(arg1, arg2, arg3);
             } else {
                 throw MessengerInternal.CreateBroadcastSignatureException(eventType);
             }
         }
     }
 }



one more edit sorry, if im not being proper to the forumns, i believe the error could derive from this vital bars script, even though the compiler doesnt mention it

 /// VitalBar.cs
 /// 4 14 2012
 /// joey
 /// this class is responsible for displaying a vital for the player character or a mob
 /// </summary>
 using UnityEngine;
 using System.Collections;
 
 public class VitalBar : MonoBehaviour {
     public bool _isPlayerHealthBar;                 //this bool value tells us if this the player health or mob healthbar
     
     private int _maxBarLength;                      //how long the vital bar can be at its maximum health
     
     private int _curBarLength;                     // this is the current length of the vital bar
     
     private GUITexture _display;
     
     
     // Use this for initialization
     void Start () {
     //   _isPlayerHealthBar = true;
         
         _display = gameObject.GetComponent<GUITexture>();
         
         _maxBarLength = (int)_display.pixelInset.width;
         
         OnEnable();
         
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     //this method is called when the gameObject is enabled
     public void OnEnable() {
         if(_isPlayerHealthBar)
         Messenger<int, int>.AddListener("player health update", OnChangeHealthBarSize);
    else {
         ToggleDisplay(false);
         Messenger<int, int>.AddListener("mob health update", OnChangeHealthBarSize);    
         Messenger<bool>.AddListener("show mob vitalbars", ToggleDisplay);
       }    
     }
     //this method is called when the gameobject is disabled
     public void OnDisable() {
         if(_isPlayerHealthBar)
         Messenger<int, int>.RemoveListener("player health update", OnChangeHealthBarSize);
       else {
                 
         Messenger<int, int>.RemoveListener("mob health update", OnChangeHealthBarSize);
         Messenger<bool>.RemoveListener("show mob vitalbars", ToggleDisplay);
         }
     }
     // this method will calculate the total size of the health bar in relation to the x of health the target has left
     public void OnChangeHealthBarSize(int curHealth, int maxHealth) {
     //    Debug.Log("We heard an event: curHealth - " + curHealth + " - maxhealth - " + maxhealth);
 
      _curBarLength = (int)((curHealth / (float)maxHealth) * _maxBarLength);  //this calculates the current bar length based on the health %
      
         //_display.pixelInset = new Rect(_display.pixelInset.x, _display.pixelInset.y, _curBarlength, _display.pixelInset.height);
         _display.pixelInset = CalculatePosition();
     }
     
     //setting the healthbar to the player or mob
     public void SetPlayerHealth(bool b) {
         _isPlayerHealthBar = b;
    }
     private Rect CalculatePosition() {
          float yPos = _display.pixelInset.y / 2 - 15;
         
         if(!_isPlayerHealthBar) {
             float xPos = (_maxBarLength - _curBarLength) - (_maxBarLength / 4 + 38);
             return new Rect(xPos, yPos, _curBarLength, _display.pixelInset.height);
         }
      return new Rect(_display.pixelInset.x, _display.pixelInset.y, _curBarLength, _display.pixelInset.height);
     }
     private void ToggleDisplay(bool show) {
          _display.enabled = show;
    }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bodec · Apr 14, 2012 at 03:38 PM 0
Share

at the top it says no listener found seems you need to install one and you should be set.if i recall that is a camera can't be 100% on that as its been a long time since i saw that error.

avatar image EntropicJoey · Apr 14, 2012 at 05:22 PM 0
Share

thank you, i fixed this error and posted what was causing it, but maybe that is the root of my problem, cause i have a new error lol thanks again

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CarstenHouweling · Apr 14, 2012 at 06:25 PM

Since you use all the code from the hack and slash tutorials from BurgZergArcade, why don't you ask him?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EntropicJoey · Apr 14, 2012 at 07:27 PM 0
Share

well i didnt want to bother him with my little questions... thanks for your crappy attitude =]

avatar image EntropicJoey · Apr 14, 2012 at 07:29 PM 0
Share

and also i already solved this issue so your comment was for nothing lol

avatar image
0

Answer by Grayie · Jul 26, 2012 at 09:38 AM

Hey, Joey. Have you fixed your "new" problem? I've got the same. Don't know what to do. All codes are the same.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joeyaaaaa · Jul 27, 2012 at 07:57 AM 0
Share

The fix is written at the top

avatar image Grayie · Jul 27, 2012 at 08:54 AM 0
Share

So, I got "show mob vital bars" everywhere, and nothing. Error: "broadcasting message show mob vital bars but no listener found", when i press "tab". It just targeting my first mob, then target "none", then again it t. first mob, "none", etc... There are also 2 "NullReferenceException" errors in VitalBars.cs (lines with "ToggleDisplay" function) and 1 in Game$$anonymous$$aster.cs 8[

avatar image joeyaaaaa · Jul 29, 2012 at 09:26 PM 0
Share

hope you fix this, but it sounds like some of your errors might be cause somethings not attached to something or what not, im not such a great scripter so im sorry i cant help you much lol

avatar image
0

Answer by joeyaaaaa · Jul 27, 2012 at 09:19 AM

The new error was fixed and irrelevant I believe, I don't remember but the fix is written at the top

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 3d Elevator Script Not Working Properly 0 Answers

implement own OpenGL code in script 1 Answer

< INT_MIN || f > INT_MAX targeting error 1 Answer

Putting variable into new Unity GUI InputField and then Acessing that variable 1 Answer

Does anyone know how to embed AIML? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges