Blitz3D+ Command Reference

CreateUuid$ ( )

Parameters

None.

Description

Creates a random version-4 UUID as lowercase canonical text.

A UUID is a permanent identity you can stamp on anything - a save slot, a spawned monster, a player profile, a level built in your editor - and trust to be unique across machines without any central counter. Two games on opposite sides of the world will not mint the same id, which is exactly what save files, cloud sync and networking need.

The randomness comes from the operating system's cryptographic generator (not Rand/SeedRnd, which cannot provide this guarantee), with the RFC 9562 version and variant bits set: the result is always lowercase 8-4-4-4-12 form like "1b4e28ba-2fa1-4d3b-a3f9-d9c0d1c8e4f2", with '4' as the version digit. It always passes UuidValid and is already in the canonical form NormalizeUuid produces, so fresh ids compare as plain strings.

Store ids as JSON strings in your saves, or as 16 raw bytes in binary formats via UuidToBytes. CreateUuid is main-thread-only - a Job worker cannot mint ids, so generate them up front and pass them in.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: UuidValid, NormalizeUuid, UuidToBytes, UuidFromBytes.

Example

; CreateUuid Example
; ------------------
; Requires Extended mode.

; Give three freshly spawned game objects permanent identities.
; CreateUuid uses the OS cryptographic random generator, so ids
; are unique across machines - perfect for save files and networking.
player_id$=CreateUuid()
monster_id$=CreateUuid()
chest_id$=CreateUuid()

Print "player_id  = "+player_id
Print "monster_id = "+monster_id
Print "chest_id   = "+chest_id
Print ""

; Every id is a lowercase RFC version-4 UUID:
; the 15th character is always the version digit '4'
Print "Version digit of player_id: '"+Mid(player_id,15,1)+"'"
Print "Valid according to UuidValid: "+UuidValid(player_id)
Print ""
Print "Run the example again - the ids are different every time."

Print ""
Print "Press any key to close the example"
WaitKey

End

Index