Search Unity

Question Game Programming with Unity and C#: A Complete Beginner’s Guide, Casey Hardman

Discussion in 'Getting Started' started by SHARYPOWER, Apr 18, 2022.

  1. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    Hi, have anybody got this book?
    Game Programming with Unity and C#: A Complete Beginner’s Guide
    Casey Hardman


    I need some help. I'am doing the part with tower defense game - pages around 387 and further.

    My problem (or the book problem) is the variable named: "gold" doesn't exist. If you have this book can you check where that variable is declared??

    Thank you !!!!
     
    Last edited: Apr 18, 2022
  2. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    Code (CSharp):
    1. if (towerPrefabToBuild != null)
    2. {
    3. //If there is no tower in that slot and we have enough gold to
    4. build the selected tower:
    5. if (!towers.ContainsKey(highlighter.position) && gold >=
    6. towerPrefabToBuild.goldCost)
    7. {
    8. BuildTower(towerPrefabToBuild,highlighter.position);
    9. }
    10. }
    there is more places where "gold" appear but this one above is the first one i think.

    (5th line at the end)
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Does the book have a download location for the files? You could also use your phone to take photos of the code from the book and paste it here. Just search the code you've written for the word "gold" to find the first occurrence, hopefully the declaration.
     
  4. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    Ok, but i can't share whole code. It has around 350 lines and I'am writing in a different language so it will be very confusing to you. The thing is the "gold" variable is not declared and I am getting an error.

    So somebody have to have that book at home or maybe somebody was doing it not long ago??
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you elaborate, in a different language? Are you not coding in C# and English? Does the book not have a download location for the files? Did you search your file for the first occurrence? There is a good chance no one reading this post will have the book.
     
  8. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    Ok I found some files on GitHub and I think I found the "problem". Give me one second.
     
  9. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    First image: Screenshot from the book:

    Second image: from the Git Hub:


    Now I think you understand... Basically the gold variable is missing in the book... this is not good :(

    I'am going now to see if it works..
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  11. SHARYPOWER

    SHARYPOWER

    Joined:
    Jan 19, 2022
    Posts:
    17
    The issue about my previous post was about my wrong "interpretation" of some part of the book. But here in this post the main issue is the gold variable is missing in the book!! which is the shame for the author... I also spotted other small issues like wrong figure image or a single word (but not in the code).

    Thank you for your help anyway because I didn't think before to find the book files on the internet.
     
    JeffDUnity3D likes this.