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

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 !!!

if (towerPrefabToBuild != null)
{
//If there is no tower in that slot and we have enough gold to
build the selected tower:
if (!towers.ContainsKey(highlighter.position) && gold >=
towerPrefabToBuild.goldCost)
{
BuildTower(towerPrefabToBuild,highlighter.position);
}
}

there is more places where “gold” appear but this one above is the first one i think.

(5th line at the end)

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.

you can download this book for free (lol) here (just found it when i was looking for the answer)

I would prefer not to download from that location. Please share the code in question

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??

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.

Ok I found some files on GitHub and I think I found the “problem”. Give me one second.

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 :frowning:

I’am going now to see if it works…

It could be the same issue that you had previously, you need to follow the book step by step and not skip ahead Array problem (working with the book)

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.

1 Like