Share Your Code

GUID Creation Module

Posted by drbigfresh, Posted on February 22, 2012

GitHub URL: 
https://github.com/ScottPhillips/GUID-Creation-Module-for-CoronaSDK

I needed a way to generate unique IDs for something I was working on, and since Corona doesn't have built in support for guids, and since the only other thing out there had dependencies, I wrote my own. I can't say that they adhere entirely to the spec., but they look right, and they're guaranteed to be unique, so it was good enough for me.

They looks like this:

DA3C1235-EAE1-2524-7798-63D2D8EBC487

846521A4-D962-AA9C-4EA9-566A6931D287

424EF5CA-133B-8974-9D59-2E2974166874

Usage is super simple:

On a normal something.lua page

--Require the module at the top of your page:

local guid = require "guid"

--Then call generate() to make one:

print(guid.generate());

If you're using StoryBoard

In your main.lua:

--Require StoryBoard

local storyboard = require "storyboard"

--Create a table to hold modules:

storyboard.modules = {}

--Add the GUID Module

storyboard.modules.guid = require('guid')

--Then call generate() to make one in any of your scene files:

print(storyboard.modules.guid.generate());

If you come across any bugs or better ways of doing it, post em over on github and I'll fix/add them.


Replies

Ninja Pig Studios
User offline. Last seen 3 days 6 hours ago. Offline
Joined: 26 Jan 2011

I like this! Really cool, it could be really useful for multiplayer games.

Regards,
Jordan Schuetz
Ninja Pig Studios

mroberti
User offline. Last seen 3 hours 9 min ago. Offline
Joined: 20 Nov 2010

Epic! Thank you!

jonjonsson
User is online Online
Joined: 30 May 2011

Hi, I have been using this but then I was having some strange errors and tracked it back to this module.

I then tested:

1
2
3
for i = 1, 100, 1 do
  print(guid.generate())
end

and after 20 loops it starts returning False.

In line 22 in the module you have:
if(guid.loops > 20) then return false; end
which is the cause of the problem I believe.