method return type is incompatible
I have assigned two variables the return value of functions from other scripts. I try to take one away from the other to see whether the value is above, below or equal to 0 (win, loss or draw) However, it says that the method return type is incompatible. I cannot find where this problem could have been caused.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WinOrLoss : MonoBehaviour {
public StatPicker cardValue;
public ComputerStatPicker compValue;
public void Winner ()
{
int playerCard = cardValue.StatClicked();
int compCard = compValue.CardStatClicked();
if (playerCard - compCard > 0)
{
Debug.Log("Winner");
}
if (playerCard - compCard < 0)
{
Debug.Log("Loser");
}
if (playerCard - compCard == 0)
{
Debug.Log("Draw");
}
}
}
CardStatClicked()
public int CardStatClicked ()
{
Transform valueOfParent = this.transform.parent;
TextMeshProUGUI textOfParent = valueOfParent.GetComponent<TextMeshProUGUI>();
string compValueString = textOfParent.text;
return int.Parse(compValueString);
}
StatClicked()
public int StatClicked ()
{
Transform value = this.transform.parent;
TextMeshProUGUI text = value.GetComponent<TextMeshProUGUI>();
string valueText = text.text;
return int.Parse(valueText);
}
We need the line and the other code, but I'm guessing either
int playerCard = cardValue.StatClicked(); int compCard = compValue.CardStatClicked();
.
Are not returning an int.
Can we see the functions StatClicked() & CardStatClicked()?
You should use Convert.ToInt32(valueText)
ins$$anonymous$$d of int.Parse(valueText)
@RobAnthem This doesn't work and says convert does not exist. Do i need a using ___ to get it to work?
However, this doesn't fix the problem of the method return types being incompatible
Who and How Winner
is called? Can you show the full error message?
@Hellium Winner Is called through a button's onClick value.
ArgumentException: method return type is incompatible
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.$$anonymous$$ethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:190)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.$$anonymous$$ethodInfo method) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:276)
UnityEngineInternal.NetFxCoreExtensions.CreateDelegate (System.Reflection.$$anonymous$$ethodInfo self, System.Type delegateType, System.Object target) (at C:/buildslave/unity/build/Runtime/Export/WinRT/NetFxCoreExtensions.cs:38)
UnityEngine.Events.InvokableCall..ctor (System.Object target, System.Reflection.$$anonymous$$ethodInfo theFunction) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:143)
UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:406)
UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:569)
UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:736)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:772)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
Do you have any coroutines (IEnumerators) in your code? Could you share them?
Your answer
Follow this Question
Related Questions
call any method 1 Answer
MoveTowards instantly repositioning object to target position 2 Answers
Get Set Return method, properties stuff? 2 Answers
Player not activating method 0 Answers
Storing functions to use later 0 Answers