TGC Codebase Backup



Registration Key (file reading and writing) by Sph!nx

4th Dec 2009 6:12
Summary

A full example on how to create, read and write to a file to setup a simple registration for your game/program.



Description

It's very basic and for newbies to learn file reading and writing.

This code will show you how to make a file, enter a code, write the code to the file. Next time you load the program, and the file is present, the code procedure will be skipped.

I posted this to give something back to the community that gave so much to me! I'm still learning, so if you have comments or critics, please let me know!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    // Registration! (place this at start of app!) CODE BY SPH!NX!
GLOBAL ID$
ID$ = "0"

IF NOT FIlE EXIST ("registration.dat")

	MAKE FILE ("registration.dat")
	if file exist("registration.dat") then delete file "registration.dat"
	
	PRINT ""
	PRINT " Enter Registration Key "
	INPUT " > ", ID_input$
	IF ID_input$ = "T34M-D3V3D-1Z-C001" THEN ID$ = "T34M-D3V3D-1Z-C001"

	IF ID$="T34M-D3V3D-1Z-C001"
		
		PRINT " Registration Accepted!"		
		OPEN TO WRITE 1, ("registration.dat")
		WRITE STRING 1, ID$
		wait 1000
		CLOSE FILE 1
	
	ELSE
	
		PRINT " Registration Failed!"
		if file exist("registration.dat") then delete file "registration.dat"
		WAIT 2000
		END
	ENDIF
	
ENDIF

IF FILE EXIST ("registration.dat")

	OPEN TO READ 1, ("registration.dat")
	READ STRING 1, ID$
	CLOSE FILE 1

	IF ID$ = "T34M-D3V3D-1Z-C001"
		
		GOTO _proceed		
	ELSE
		
		PRINT ""
		PRINT " Illegal registration key used!"
		WAIT 2000
		END
		
	ENDIF

ENDIF

_proceed: