Why isn't System.Guid.NewGuid() used to create unique IDs?

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
firefire
Posts: 12
Joined: Fri Jun 10, 2016 6:48 am

Why isn't System.Guid.NewGuid() used to create unique IDs?

Post by firefire »

Hello,

There's a script called ES2UniqueID that is used in an example to generate unique IDs in order to create an automatic saving system.

I'm running into issues with the GenerateUniqueID() generating duplicate IDs because I'm destroying and then creating again objects.

Code: Select all

private static int GenerateUniqueID()
	{
		// If no unique IDs have yet been set, use zero.
		if(uniqueIDList.Count == 0)
			return 0;
		// Get the last (and thus highest) number in the list
		// and then add 1 to it to get a new unique number.
		return uniqueIDList[uniqueIDList.Count-1].id+1;
	}
I'm wondering why this custom method of generating ID is used instead of using something that is already built in like:

Code: Select all

System.Guid.NewGuid().ToString()
Am I missing something important here?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why isn't System.Guid.NewGuid() used to create unique ID

Post by Joel »

Hi there,

As it's intended as an example, we've tried to keep it as simple as possible. If you wish to modify it to use GUIDs, that will also work.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked