Jump to content
  • Advertisement
CubeUser

Unity How to make an Idle game or incremental game?

Recommended Posts

Hello, I am trying to get a grasp on those "Idle games/Clicker games" or "Incremental games". I want to write one in Unity3D, but I am not sure how to deal with those high numbers. I wonder how they do to present this? Does anyone here know a trick? Just to make one thing clear first though: I don't think they are all using "Arbitrary precision data types", Sure you _can_ use them but that would probably be like using military/space spec. components in a game console (you _can_ but very much more expensive (creepingly slow in this case)). There are several games out there from several companies, for several platforms, including small battery driven devices, and those do simply not have the power to shuffle that much data without becoming too battery/CPU hungry. So hence I am sure they must have different solutions. So is there any idea on how to implement this _without_ using "Arbitrary precision"? I have googled for a clear description with well commented C# code for use with Unity3D but nothing. Some Youtube video however suggested that for each "Exponent" they divided or multiplied the main number with 1000 but that was not explained either fully. And asking Hyper Hippo would not work I am sure. (As for the rest of the game I am sure there are tutorials, how difficulty is controlled and so on.)
I intend to use Unity3D/C#

Share this post


Link to post
Share on other sites
Advertisement

So you never said what the problem with high numbers is for you so I am assuming that you reached the int limit: 2,147,483,647

First thing. If you use values like a 100 for each tic/click/whatEver then keeping score and dividing by 100 is a easy way to store data.

So player does 2 click gets score as 200 you divide by 100 and store the int as 2. So you store the clicks not the score.

 

The whole point behind making a clicker game is to solve the problem of storing numbers, so read the following at your own risk:

Spoiler

 

The common way of storing numbers like this is to use tens, I forgot what it's called but here is a example:


int one;
int ten;
int hundred;
int thousand;

//So we can store player score as:
//player score = 1500
thousand = 1;
hundred  = 5;
ten      = 0;
one      = 0;

Debug.Log(string.Format("Player Score: {0}{1}{2}{3}", thousand, hundred, ten, one));
//Returns: "Player Score: 1500"

As you can see there is no limit to the above system and all you need to do is add a new int for every new digit. Because each only uses 0-9 you never cross the int limit.

 

 

Share this post


Link to post
Share on other sites

That's one problem yes, the limit. Another is, how to have multiple "adders"? (Called "Profits" in AdCap), All of those need to be able to store data the same way, and also, how to do maths between this, for example if an adder is supposed to multiply it's value by a vertain number. Doing one of the four calculation operations (+-*/) on them, they need to be compatible somehow. But how to do that?

Share this post


Link to post
Share on other sites
1 hour ago, CubeUser said:

That's one problem yes, the limit. Another is, how to have multiple "adders"?

You would make a class for handling the numbers.

That class would have a get and a set function. Inside the class you would store numbers like that but when dealing with the math you would getplayer score as a structure made from those numbers. You would do the math per int channel and then store it back again.

Share this post


Link to post
Share on other sites
Just now, Scouting Ninja said:

You would make a class for handling the numbers.

That class would have a get and a set function. Inside the class you would store numbers like that but when dealing with the math you would getplayer score as a structure made from those numbers. You would do the math per int channel and then store it back again.

How would all that look like? How would the math be done?

Share this post


Link to post
Share on other sites
4 hours ago, CubeUser said:

How would all that look like? How would the math be done?

Piece by piece. You would use an array to make things smoother.

Tried and tested:

Spoiler

 


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {
	//This is a class
	public class KeepScore
	{
		//Here we define our variables
		public int[] ThousandMax; //The [] is a array
        
        //When we create a new copy we can input these values. Note it's the class input
        //It has the same name as the class
		public KeepScore(int InThousands, int InHundreds, int InTens, int InOnes) 
		{
          //Here we say how many itmes is in the array then what each is
			ThousandMax = new int[4];
          
			ThousandMax[0] = InThousands;//arrays start at 0 so our 4 array is 0-3
			ThousandMax[1] = InHundreds;
			ThousandMax[2] = InTens;
			ThousandMax[3] = InOnes;
		}
		//The above class now keeps the score
	}

	//We make a normal function to add the scores piece by piece
	public KeepScore AddTwoScores(KeepScore InScoreA, KeepScore InScoreB){
      
		KeepScore OutScore = new KeepScore
			InScoreA.ThousandMax[0] + InScoreB.ThousandMax[0],//Add the Thousands
			InScoreA.ThousandMax[1] + InScoreB.ThousandMax[1],//Add the Hundreds
			InScoreA.ThousandMax[2] + InScoreB.ThousandMax[2],//Add the Tens
			InScoreA.ThousandMax[3] + InScoreB.ThousandMax[3]);//Add the ones
		
		//Next we check if one value exceeds 9
		int IndexCounter = 0;
		foreach ( int increment in OutScore.ThousandMax){
			if (increment > 9) {
				OutScore.ThousandMax[IndexCounter] -= 10;//if it does subtract 10
				if (IndexCounter > 0){ //Don't add if it is more than a thousand 0 is the first array item and is thousand
					OutScore.ThousandMax[IndexCounter-1] +=1; //Remember the larger number is lower in the array
				} 
			}
			IndexCounter +=1;
		}

			return OutScore; //Return it as a score
	}
	//Lets make a string converter
	public string ScoreToString(KeepScore InScore){
		string OutString = string.Format ("{0}{1}{2}{3}", InScore.ThousandMax[0], InScore.ThousandMax[1], InScore.ThousandMax[2], InScore.ThousandMax[3]);
		return OutString;
	}

	//now lets use what we made
	void Start(){//Unity calls this at the start
		//Make two scores
		KeepScore Player1Score = new KeepScore (1,2,0,0);
		KeepScore Player2Score = new KeepScore (0,9,0,0);

		KeepScore Total = AddTwoScores (Player1Score, Player2Score);

		print(ScoreToString(Total)); //returns : 2100

		//Now lets try to break it
		Player1Score = new KeepScore (9,9,9,9);
		Player2Score = new KeepScore (9,9,9,9);

		Total = AddTwoScores (Player1Score, Player2Score);

		print(ScoreToString(Total)); //returns : 9998 because it is 1-9998 but we don't support that much
	}
}

 

 

 

 

You could also do it as a function in the class. 

Here I turned the add function to auto so that you don't have to type each one. I just wanted to show how it works first.

Spoiler

 


	public KeepScore AddTwoScores(KeepScore InScoreA, KeepScore InScoreB){
		KeepScore OutScore = new KeepScore(0,0,0,0); //Make a empty one
		int IndexCounter = 0;
		foreach (int increment in OutScore.ThousandMax){
          //##########Change###############
			//Add each value
			OutScore.ThousandMax[IndexCounter] = 
				InScoreA.ThousandMax [IndexCounter] + InScoreB.ThousandMax [IndexCounter];//Add the increment
          //##########Change###############

			//Next we check if one value exceeds 9
			if (OutScore.ThousandMax[IndexCounter] > 9) {
				OutScore.ThousandMax[IndexCounter] -= 10;//if it does subtract 10
				if (IndexCounter > 0){ //Don't add if it is more than a thousand 0 is the first array item and is thousand
					OutScore.ThousandMax[IndexCounter-1] +=1; //Remember the larger number is lower in the array
				} 
			}

			IndexCounter += 1;
		}

			return OutScore; //Return it as a score
	}

 

 

If I do any more than this for you it would be my game. Good luck :)

Share this post


Link to post
Share on other sites

Thank you :-) It's quite a lot so I will save this to disk. In the now obsolete Microsoft VisualBasic 6 there was a data type called "Double" that could save really huge values, it could reach as far as "Adventure Capitalist". But I am not sure if that data type is in Unity C# and if it is, I doubt it is possible to cast the values to a string to check what number somes after "+E" to control things or translate. I guess it was there for some database purpose. I will experiment and see if I can find something similar once I get this you helped me with clear :-D

Share this post


Link to post
Share on other sites
1 hour ago, CubeUser said:

"Double" that could save really huge values

They are in all languages that I know.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/double

10 hours ago, Scouting Ninja said:

So you never said what the problem with high numbers is for you so I am assuming that you reached the int

That is why I wrote this. I assumed you knew there was doubles and longs but for some reason could not use them. So I showed that way instead.

 

Edit:

I feel I should clear up something.

Doubles are inaccurate and Longs don't store much higher numbers.

int     = int32 = 2 147 483 647

long = int64 = 9 223 372 036 854 775 807

So if you started your game in the thousands it isn't that long before it breaks past int64.

 

Doubles are unstable and in your game this will matter.

for example: 1/3 will produce 0.333 to what ever number the double can hold. However it will be wrong because it's a infinite number stored on a finite computer.

To take advantage of the doubles storing you need to devide, so sooner or later you will get mistakes. Because the integer part of a double has a similar limit to a int64.

Also subtracting a double from a double will often lead to inaccuracies.

 

For this reason games that use large numbers often use the system I showed before.

Edited by Scouting Ninja

Share this post


Link to post
Share on other sites
On 2017-11-06 at 1:49 AM, Scouting Ninja said:

They are in all languages that I know.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/double

That is why I wrote this. I assumed you knew there was doubles and longs but for some reason could not use them. So I showed that way instead.

 

Edit:

I feel I should clear up something.

Doubles are inaccurate and Longs don't store much higher numbers.

int     = int32 = 2 147 483 647

long = int64 = 9 223 372 036 854 775 807

So if you started your game in the thousands it isn't that long before it breaks past int64.

 

Doubles are unstable and in your game this will matter.

for example: 1/3 will produce 0.333 to what ever number the double can hold. However it will be wrong because it's a infinite number stored on a finite computer.

To take advantage of the doubles storing you need to devide, so sooner or later you will get mistakes. Because the integer part of a double has a similar limit to a int64.

Also subtracting a double from a double will often lead to inaccuracies.

 

For this reason games that use large numbers often use the system I showed before.

Do why not implement a division routine that that divides the double value and then truncates like for instance  "int(value1*100)/3"/10?  (Somehow the result should be cast back to a double). I mean anything divided with 3 will be inaccurate anyway sooner or later anyway  as it is an infinite number of 3's. I also searched the web for Adventure Cppitalist and "double" and it came up that someone said it uses that type. Also there are more things to the original method you mentioned: Those large values are also found in upgrades, their prices and also how they influence the "Score". They must be able to also subtract, multiply and divide. How are those operations done on your array example?

Edited by CubeUser

Share this post


Link to post
Share on other sites
9 hours ago, CubeUser said:

Do why not implement a division routine that that divides the double value and then truncates like for instance  "int(value1*100)/3"/10?

Because you convert to a int. So you lose the precision of the double. If you use a int at any time it will become your bottleneck.

You will basically cut away the number if it's larger than what the int can take. For example:

double MyDouble = 0.1 111 111 111 999
MyDouble  * 10 000 000 000 000 = 1 111 111 111 999

(int)MyDouble * 10 000 000 000 000 = -2147483648 //This is the int failing to store the value of the double.

So using your above trick you would be limited to what a int can store. So your back to problem one, int can't store much.

9 hours ago, CubeUser said:

. I mean anything divided with 3 will be inaccurate anyway sooner or later anyway  as it is an infinite number of 3's.

Yes exactly. You can't use a computer to divide by 3. It's one of the common problems you will get while working with games.

To avoid division errors you can use multiplication  1 /2 = 1 *0.5 = 0.5;    100 *0.5 = 50;

This keeps things in what number system you are using because 1/3 =0,3333333(float) but 1 * 0.333  = 0.333. So it's a easy way to limit numbers without using int or min and max.

9 hours ago, CubeUser said:

I also searched the web for Adventure Cppitalist and "double" and it came up that someone said it uses that type.

You are free to use it. It's your own choice. Doubles should do all you need.

9 hours ago, CubeUser said:

their prices and also how they influence the "Score". They must be able to also subtract, multiply and divide. How are those operations done on your array example?

Piece by piece using basic math. So 120 /2 

The key is to work from the Ones upwards.

Ones 0/2 = 0;

Tens 2/2 = 1;

Hundreds  1/2= 0.5; // We use a if statement to send the 5 to the tens.// Tens is now 6

= 0 6 0 = 120 /2 = 60;

555 / 4 = 138.75

Ones 5/4 = 1.25 // We discard the 0.25 as it isn't supported.

Tens 5/4  = 1.25 // We discard 0.05 but keep the 2 as a one// Ones is now 3

Hundreds = 1.25// We add 2 to Tens and 5 to ones. // Tens is now 3 // Ones is now 8

= 1 3 8 = 555/4 = 138.

 

This system has a name I just can't remember what it is. It's used in large 3D games to keep track of measurements. Like in space games. In fact I learned it for space games. I had whole planets shaking around in space because of the doubles.

 

This number system Is a shortcut. Where instead of trying to store data smartly on your PC, you hack it and store each ten in it's own 2-4 bytes. A googol is 1 to the 100th power. You would need a 101 int to store it using the system I showed. That is 4* 101 = +/- 404bytes depending on many factors, less than a single profile picture.

A googol is 101 digits, looks like this 10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000

A double can store 52 + 971 = 1023 digits. More than 10 googols.

So for a game where players only see the numbers they won't notice the errors of the doubles. You can use them safely.

Again, your original question did not make clear your problem, so I assumed you had problems with using doubles and decimals.

Edited by Scouting Ninja

Share this post


Link to post
Share on other sites

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Hellados
      Hello guys, my name is Giorgi and i'm newbie game developer i'm learning Pixel art and after pixel art  i want learn C# and don't know how and where start i'm bad with programming language and know only HTML/CSS
    • By D34DPOOL
      Edit Your Profile D34DPOOL 0 Threads 0 Updates 0 Messages Network Mod DB GameFront Sign Out Add jobEdit jobDeleteC# Programmer for a Unity FPS at Anywhere   Programmers located Anywhere.
      Posted by D34DPOOL on May 20th, 2018
      Hello, my name is Mason, and I've been working on a Quake style arena shooter about destroying boxes on and off for about a year now. I have a proof of concept with all of the basic features, but as an artist with little programming skill I've reached the end of my abilities as a programmer haha. I need someone to help fix bugs, optomize code, and to implent new features into the game. As a programmer you will have creative freedom to suggest new features and modes to add into the game if you choose to, I'm usually very open to suggestions :).
      What is required:
      Skill using C#
      Experience with Unity
      Experience using UNET (since it is a multiplayer game), or the effort and ability to learn it
      Compensation:
      Since the game currently has no funding, we can split whatever revenue the game makes in the future. However if you would perfer I can create 2D and/or 3D assets for whatever you need in return for your time and work.
      It's a very open and chill enviornment, where you'll have relative creative freedom. I hope you are interested in joining the team, and have a good day!
       
      To apply email me at mangemason@yahoo.com
    • By Andrew Parkes
      I am a talented 2D/3D artist with 3 years animation working experience and a Degree in Illustration and Animation. I have won a world-wide art competition hosted by SFX magazine and am looking to develop a survival game. I have some knowledge of C sharp and have notes for a survival based game with flexible storyline and PVP. Looking for developers to team up with. I can create models, animations and artwork and I have beginner knowledge of C sharp with Unity. The idea is Inventory menu based gameplay and is inspired by games like DAYZ.
      Here is some early sci-fi concept art to give you an idea of the work level. Hope to work with like minded people and create something special. email me andrewparkesanim@gmail.com.
      Developers who share the same passion please contact me, or if you have a similar project and want me to join your team email me. 
      Many thanks, Andrew.

    • By davejones
      Is there a way to automatically change the start position of an animation? I have a bunch of animations set up on 3D models in unity. The issue is that I need to move the 3D models, however when I do so the animation start positions are not updated and I have to do it manually.

      Changing the transform of key frames is time consuming with the amount of animations I have, so I was wondering if there was a way to do it automatically?
    • By mike44
      The reference assemblies for framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

      Hi
      what to do with the above error in ms code/Unity3d Project on Ubuntu 18.04? I've installed it like:
      https://www.microsoft.com/net/learn/...ux/ubuntu18-04
      Many thanks
    • By N Drew
      I am working on a 2D SideScroller game in my own made game engine using SFML and C++.I am searching for 2D artists,especially pixel artist for making and animating characters,backgrounds and other props that can be made in any Drawing Program.The artist will become part of the team of Hammer Studios and he got a part of the Revenue Sharing.If you are interested send me a mail at:ghiurcutaandrei@gmail.com .If you are not an artist but you want to be a part of our Team,Soon we will be recruiting an C++ AI programmers that worked in SFML/OpenGL.
      We work together using Discord.

    • By Dave Haylett
      Hi.
      I have pulled in five NuGet packages for my Visual Studio 2017 project, however when I build the project, VS spits out 10 .DLL and .XML files in the root of the binary folder, to do with the packages. Can't I shove them into a \packages folder so the user doesn't see these ugly resources next to the .exe file?
      I've Googled moving the packages but the only responses seem to be around moving the installation folder of the NuGet packages on the local machine, as opposed to where VS builds them to.
    • By MoreLion
      hey all! We are looking for members for our Unity horror game! 
      Here’s the story:
      After a deadly virus plunges the world into chaos killing 85% of the human population there are now what they call “zones” these zones are watched very closely by the surviving government, people are checked every day for the virus, even if you touch the spit or any human waste or fluids of the victim who is infected, you will die. But one day, people in the west zone start to go missing, 1 woman goes outside the walls to uncover the mystery, is there more to the virus than meets the eye?, That is where your story starts.
      This game is not a long development game, I have loads other game ideas,
      I will also allow you to have a bit of creative freedom if you wish to add or share a idea!
      And no, it’s not a zombie game lol I feel like zombie games are too generic, in this game you will encounter terrifying beasts!
      There is some concept art one of our concept artists have made
      If interested email liondude12@gmail.com
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631359
    • Total Posts
      2999539
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!