can somebody help me with my errors in my C# script

this is my error:

Assets/Scripts/shops/Shop_Access.cs(71,19): error CS0019: Operator >=' cannot be applied to operands of type int’ and string'** **Assets/Scripts/shops/Shop_Access.cs(72,16): error CS0019: Operator -=’ cannot be applied to operands of type int' and string’
Assets/Scripts/shops/Shop_Access.cs(80,19): error CS0019: Operator >=' cannot be applied to operands of type int’ and string'** **Assets/Scripts/shops/Shop_Access.cs(81,16): error CS0019: Operator -=’ cannot be applied to operands of type int' and string’
Assets/Scripts/shops/Shop_Access.cs(89,19): error CS0019: Operator >=' cannot be applied to operands of type int’ and string'** **Assets/Scripts/shops/Shop_Access.cs(90,16): error CS0019: Operator -=’ cannot be applied to operands of type int' and string’
Assets/Scripts/shops/Shop_Access.cs(98,19): error CS0019: Operator >=' cannot be applied to operands of type int’ and string'** **Assets/Scripts/shops/Shop_Access.cs(99,16): error CS0019: Operator -=’ cannot be applied to operands of type int' and string’
this are my scripts:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;

public class Shop_Access : MonoBehaviour {
   
    public GameObject ShopInventory;
    public GameObject Item01Text;
    public GameObject Item02Text;
    public GameObject Item03Text;
    public GameObject Item04Text;
    public GameObject ItemComplection;
    public GameObject CompleteText;

    public GameObject ThePlayer;

    public GameObject Item01PriceBox;
    public GameObject Item02PriceBox;
    public GameObject Item03PriceBox;
    public GameObject Item04PriceBox;

    public int ItemPurchaseNumber;
    public GameObject NotEnough;

    void OnMouseDown () {
        ThePlayer.GetComponent<FirstPersonController> ().enabled = false;
            ShopInventory.SetActive (true);
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
            GlobalShop.ShopNumber = 1;
        Item01Text.GetComponent<Text> ().text = "" + GlobalShop.Item01;
        Item02Text.GetComponent<Text> ().text = "" + GlobalShop.Item02;
        Item03Text.GetComponent<Text> ().text = "" + GlobalShop.Item03;
        Item04Text.GetComponent<Text> ().text = "" + GlobalShop.Item04;
        Item01PriceBox.GetComponent<Text> ().text = "Kosten: " + GlobalShop.Item01Price;
        Item02PriceBox.GetComponent<Text> ().text = "Kosten: " + GlobalShop.Item02Price;
        Item03PriceBox.GetComponent<Text> ().text = "Kosten: " + GlobalShop.Item03Price;
        Item04PriceBox.GetComponent<Text> ().text = "Kosten: " + GlobalShop.Item04Price;
    }

    public void Item01 () {
        ItemComplection.SetActive (true);
        CompleteText.GetComponent<Text> ().text = "Weet je zeker dat je een " + GlobalShop.Item01 + " wilt kopen";
        ItemPurchaseNumber = 1;
    }
    public void Item02 () {
        ItemComplection.SetActive (true);
        CompleteText.GetComponent<Text> ().text = "Weet je zeker dat je een " + GlobalShop.Item02 + " wilt kopen";
        ItemPurchaseNumber = 2;
    }
    public void Item03 () {
        ItemComplection.SetActive (true);
        CompleteText.GetComponent<Text> ().text = "Weet je zeker dat je een " + GlobalShop.Item03 + " wilt kopen";
        ItemPurchaseNumber = 3;
    }
    public void Item04 () {
        ItemComplection.SetActive (true);
        CompleteText.GetComponent<Text> ().text = "Weet je zeker dat je een " + GlobalShop.Item04 + " wilt kopen";
        ItemPurchaseNumber = 4;
    }
    public void CancelTransaction () {
        ItemComplection.SetActive (false);
        ItemPurchaseNumber = 0;
        NotEnough.SetActive (false);
        }

    public void CompleteTransaction () {
        if (ItemPurchaseNumber == 1) {
            if (GlobalCash.CurrentCoins >= GlobalShop.Item01Price) {
                GlobalCash.CurrentCoins -= GlobalShop.Item01Price;
                ItemComplection.SetActive (false);
            } else {
                NotEnough.SetActive (true);
            }
        }

        if (ItemPurchaseNumber == 2) {
            if (GlobalCash.CurrentCoins >= GlobalShop.Item02Price) {
                GlobalCash.CurrentCoins -= GlobalShop.Item02Price;
                ItemComplection.SetActive (false);
            } else {
                NotEnough.SetActive (true);
            }
        }

        if (ItemPurchaseNumber == 3) {
            if (GlobalCash.CurrentCoins >= GlobalShop.Item03Price) {
                GlobalCash.CurrentCoins -= GlobalShop.Item03Price;
                ItemComplection.SetActive (false);
            } else {
                NotEnough.SetActive (true);
            }
        }

        if (ItemPurchaseNumber == 4) {
            if (GlobalCash.CurrentCoins >= GlobalShop.Item04Price) {
                GlobalCash.CurrentCoins -= GlobalShop.Item04Price;
                ItemComplection.SetActive (false);
            } else {
                NotEnough.SetActive (true);
            }
        }
    }
    void Update () {
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GlobalShop : MonoBehaviour {

    public static string Item01;
    public static string Item02;
    public static string Item03;
    public static string Item04;
    public static int ShopNumber;

    public static string Item01Price;
    public static string Item02Price;
    public static string Item03Price;
    public static string Item04Price;

    void Update () {
        if (ShopNumber == 1)
        {
            Item01 = "Wood Block";
            Item01Price = "10";
            Item02 = "Black Feather";
            Item02Price = "10";
            Item03 = "Red Postion";
            Item03Price = "20";
            Item04 = "Blue Postion";
            Item04Price = "15";
        }
        if (ShopNumber == 2)
        {
            Item01 = "Iron Block";
            Item02 = "Black Feather";
            Item03 = "Red Postion";
            Item04 = "";
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GlobalCash : MonoBehaviour {

    public GameObject InventoryDisplay;
    public GameObject ShopDisplay;

    public static int CurrentCoins = 100;
    public int LocalCoins;

    void Update () {
        LocalCoins = CurrentCoins;
        InventoryDisplay.GetComponent<Text> ().text = "Coins: " + LocalCoins;
        ShopDisplay.GetComponent<Text> ().text = "Coins: " + LocalCoins;
    }
}

It’s pretty clear. You can’t compare an int and a string. If your string prices are int values, you need to convert them.

Example, if the value is 100, the string version is “100”

so, do int.parse(stringVariable) and compare that. Note that normally I suggest using tryParse, but if you know the values are ints, you should be fine. However, it has to be a value that can convert to an int. You can’t have “$100” for example as that wouldn’t convert.

1 Like

You should probably make your price variables numeric, use integers or decimals or floats, whatever will be best for your game.

public static int Item01Price;
public static int Item02Price;
public static int Item03Price;
public static int Item04Price;

You can then easily convert them to strings, but the other way is a bit tricky.

Thank you Fido789 you are great. The errors are gone.

You are welcome!

Also for your own sanity, learn about collections. Specifically arrays and lists.