Search Unity

Bug help, my code isnt working and im getting an error for ; not appearing.

Discussion in 'Visual Scripting' started by endernon, Apr 26, 2023.

  1. endernon

    endernon

    Joined:
    Jul 10, 2022
    Posts:
    4
    hi, im trying to make a card game right now but my code isn't working, is there any fix?
    code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class PlayerDeck : MonoBehaviour
    5. {
    6.     public List<card> deck = new List<card>();
    7.     public int x;
    8.     void Start()
    9.     {
    10.         x = 0;
    11.         for (int i = 0; i < 40; i++)
    12.         {
    13.             x = Random.Range(1, 4);
    14.             deck cardDatabase.cardLis[x];
    15.         }
    16.     }
    17. }
    [ICODE][ICODE]
    [/ICODE][/ICODE]
     
    Last edited: Apr 26, 2023
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Hello! When you post code on the forums, there’s a little button in the toolbar to add “Code Tags” which will format it so that it’s easier to read.

    When you get an error in the console, it will tell you which line the error is on. It’ll do its best to guess what the problem is, but it doesn’t always get it right, since it’s trying to work out your intentions.

    In this case you have a typo and an unnecessary semi-colon here:

    Code (CSharp):
    1. for (int i = 0; i < 40; i++);
    should be:

    Code (CSharp):
    1. for (int i = 0; i < 40; i++)
     
  3. endernon

    endernon

    Joined:
    Jul 10, 2022
    Posts:
    4
    i tried the fix but it didnt work, the error says that a ; is expected
     
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    it’s easier to see now you’ve added the code tags.

    What’s this line supposed to do?

    Code (CSharp):
    1. deck cardDatabase.cardLis[x];
    if you are assigning something you need

    Code (CSharp):
    1. deck = cardDatabase.cardLis[x];
     
  5. endernon

    endernon

    Joined:
    Jul 10, 2022
    Posts:
    4
    its meant to connect with my card database script and list script, I think theirs a typo though. ill go fix it right now