formatting errors converting this code!

I am trying to convert this code from C++ to C# and Unity. The game is simple roll a pair of die, check against specific numbers. if you hit the good ones, you win your bet, and get 2x the betted credits. if you hit the crap numbers, you loose your bet money.

This code is in a huge rough draft, with most things being commented out that will need replacing, and even a return where text should be generated for now.

My issue isn’t these minor nit picky errors.
It is formatting in general. I had almost all the immediate bugs worked out, but when getting to my "int PlayGame() function, unity refuses to recognize this as a function and returns a CS1519 error.

I pulled this code into Notepad++ to check my formatting. after bleeding through for a while I noticed that the code block above this specific function REFUSES to close no matter how many times I attempt to close it.

Somehow, I completely screwed up the formatting, and cannot figure it out. Everything APPEARS to be fine, but now I have a buttload of errors saying things like “unexpected symbol “else”.”

Please help me fix this, as I am close to giving up hope.

Also, while not in the scope of this question, if you help me figure out how to replace the “cout” function for unity GUI Text, I will be eternally grateful. I cannot find a decent example about setting up text and changing it on the fly through a script, except for things like health text which I can already change.

using UnityEngine;
using System.Collections;

public class Game : MonoBehaviour
{
	//bool PlayGame();
	//int die();
	//int roll(int a, int b);
	
	int Start()
	{
		if (Input.GetKeyDown("return"))
		{
			Begin();
		}
	}
	
	bool Begin()
	{
		int roundsPlayed = 0;
		int credits = 50;
		int bid = 0;
		bool done = false;
		
		while (!done)
		{
			roundsPlayed++;
			while(1)
			{
				//cout << "You currently have " << credits << " credits.

How much do you wager?

UP: Increase wager
DOWN: Decrease wager
A: Set wager

";
while(1)
{
if (Input.GetKeyDown(“up”))
{
bid++;
if (bid > credits)
{
bid = 0;
}
}
}
else if (Input.GetKeyDown(“down”))
{
bid–;
if (bid < 0)
{
bid = credits;
}
}
}
}

		if (bid == 0)
		{
			//cout << "You cannot bid 0 credits!

";
return;//temp till I fix text gui
}
else
{
//cout << "
";
break;
}
}
}

bool result = playGame()
{
	if (result == true)
	{
		//cout << "Won " << bid << " credits!

";
credits += bid;
bid = 0;
}
else
{
//cout << "Lost " << bid << " credits…
";
credits -= bid;
bid = 0;
if (credits == 0)
{
//cout << "
Left the game with no credits
left…

Played " << roundsPlayed << " games.

Press START to play again.“;
break;
}
while(1)
{
//cout << "
A: Continue game
B: Retire
“;
if (Input.GetKeyDown(“y”))
{
break;
}
if (Input.GetKeyDown(“n”))
{
done = true;
//printf(”\e[1;1H\e[2J”);
//cout << "
Left the game with " << credits << "
credits.

Played " << roundsPlayed << " games.

Press START to play again.";
break;
}
}
}

	int die()//generates a value for the die.
	{
		int value = Random.Range(1,7);
		return value;
	}
	
	int roll(int a, int b)//returns the sum of two rolls.
	{
		return a + b;
	}
	
	int PlayGame()
	{
		int roll1 = die();
		int roll2 = die();
		int total = roll(roll1, roll2);
		//cout << "Player rolled " << roll1 << " + " << roll2 << " = " << total << "

";
if (total == 7 || total == 11) //Player rolls a 7 or 11 - They win the game
{
//cout << "You won! Rolled a " << total << ".
";
return true;
}
else if (total == 2 || total == 3 || total == 12)//Player rolls one of the craps - they lose the game
{
//cout << "You lose! Rolled a " << total << ".
";
return false;
}
else //otherwise we set a point and attempt to win the game.
{
//cout << "
Rolled a " << total << ", you must now roll
until you get " << total << " again, or lose
if you roll 7!

";
int point = total;
bool win = false;
while (!win)
{
int rollA = die();
int rollB = die();
int total1 = roll(rollA, rollB);
//cout << "Player rolled " << rollA << " + " << rollB << " = " << total1 << "
";
if (total1 == 7)
{
//cout << "You lose!
";
return false;
}
else if (total1 == point)
{
return true;
}
}
}
}
}

I think the main problem here is that this code is for something super low level. The places where there’s while (1) actually defines the “game loop” at a low level, which doesn’t make sense running here since Unity is much higher level than a console program (which the original code describes). In a Unity C# script, this logic would just freeze because it’s technically an infinite loop trying to live inside Unity’s subsystems.

The solution here is to either use Unity coroutines or just define game logic in Update.

But before all that, it’s kinda obvious that you’re not too familiar with how Unity works yet, so my first recommendation is to go watch Unity’s Scripting tutorials. They’re pretty bite-sized so it shouldn’t take too much time. If you already know how to program in C++, you could probably skip the first few lessons and start at lesson 8, which starts to cover Unity’s scripting setup. (what MonoBehaviours do and the messages it receives, etc…)

Remember, when you’re programming in Unity, you’re not starting from scratch. Instead, you need to work on top of everything that’s already been built. The good thing is that you don’t need to build all those complicated things yourself. The downside is that you need to take a bit of time to learn what’s there and how to build on it; that’s less time and effort, but you still have to do it.

You can probably glean bits of logic and algorithms and things with a knowledge of C++, but you should also read up on some basics of C# syntax and standard naming so you can begin to understand C# code samples architecturally.

When you’re mostly done with all that:

(1) Temporarily, you can replace the couts with Debug.Log. That’s what behaves most like cout.

GUI Text is something that needs to be called every Update (more specifically, in OnGUI) so there are additional steps to get it to work. You could probably use a member string field and print that on screen in OnGUI. Then just modify that string where the couts are.

(2) I think Start needs to be void Start or IEnumerator Start. I’m not sure it would work as int Start.

move the bracket from 64 to the end, right now the class ends there. and either you use Debug.Log for each cout, or you create a variable for each one which you use for a GUI.Label in OnGUI