after taking so much from this forum, i think it is my turn to start giving a bit back, so i have made a tutorial on player profiling (making a profile and loading that profile, etc.)
the tutorial is in three parts and i will update the download on this post everytime i add a new part.
also, this tutorial is meant for users with at least some knowledge of DBPro (mainly in open to read and open to write commands) the rest is pretty basic, but as the i release more parts the coding will become a bit harder, but i will explain everything as much as possible
i hope you enjoy my first tutorial, please post your comments/sugestion and anything you dont understand
EDIT: also scratch the license i dont know why i put it there
EDIT: okay ive edited the tut and i hope it will be easier to understand this time
EDIT: here is a posted version:
Player Profiling
Preface:
i. Introduction
ii. Tutorial information
Topics Covered:
Part 1:
1. Reading user input
2. Creating external player file
3. Loading profiles
Part 2:
4. Adding a GUI
5. Profile encryption
6. Advanced functions
Part 3:
7. Adding polish
8. Cleaning up
9. Customizing
Preface
Introduction
Hi everyone, I am making this tutorial for the following reasons:
a) I have taken a lot of answers from you guys, so now I think it is my turn to give something in return.
b) I have a working profile system that I have been developing for my upcoming game which will form the basis of this tutorial.
If you find anything wrong in this tutorial please let me know.
But for now, enjoy.
Sam Pengilly (a.k.a. Sp3ng)
sp3ng@hotmail.com
Tutorial Information:
This tutorial is targeted at DBPro users with some experience, but it should be pretty easy for new coders, if you have a fair bit of experience though, you will absolutely breeze through this.
The profiling system contained in this tutorial can be used for a game of any genre, but with some modification it can fit that genre more, for example, I use a more militarised version of this system that I will share with you in the later parts of this tutorial.
Tutorial
Reading User Input:
For the version of our program we will be using the input command, although in the final version we will create a substitute that will allow us more flexibility.
Also for the purposes of this tutorial and to help with identification in larger code I am using the .pfl file extension and the pfl_ prefix on all variables, also as part 1 is a pretty basic part there wont be much explanation except for some remarks in the code, though explanation will be used in later, more advanced parts.
First things first, the basic stuff, reading the players profile options. This will be handled in the following way:
1. Name taken
2. Alias taken
3. Profile info stored
The code for this is as follows:
REM Gather player information
Print "Please answer the following questions, as they will create the base of your profile"
Print ""
input "Please enter your name: ",pfl_name$
input "Please enter your alias: ",pfl_alias$
Print ""
Print "Press any key to create profile"
wait key
REM Write profile info to .pfl file under the name of the players alias
REM Check if the file exists and if so delete it before writing
if file exist("Profiles\"+pfl_alias$+".pfl") = 1 then delete file "Profiles\"+pfl_alias$+".pfl"
REM Write profile information
open to write 1, "Profiles\"+pfl_alias$+".pfl"
write string 1,pfl_name$ : `Player Name
write string 1,pfl_alias$ : `Player Alias
close file 1
REM Print Information
Print "Name: "+pfl_name$
print "Alias: "+pfl_alias$
wait key
This code first asks for the players information using the Input statements:
input "Please enter your name: ",pfl_name$
input "Please enter your alias: ",pfl_alias$
all we ask for at the moment is name and a nickname to use as the profile name, but we will add more in later tutorials to customise your profiling system.
After the name and alias are collected, this information is then stored in a file,
This first part of code checks whether that particular profile exists and if so it deletes it (don’t worry, an overwrite protection system will be in later tutorials), once this is accomplished, the second part opens (creates in this case) a file to write the information in (for example a profile with a file name of: “Profiles\sp3ng.pfl”) this file is created in the games root directory and contains all the information we choose to write in it, which, at the moment is just name and alias. Also note that the order we write things into the file is the order we have to read things from the file. So if we put the name in before the alias, we have to read the name before the alias when we load the profile, failing to do this will result in very confusing variable values.
if file exist("Profiles\"+pfl_alias$+".pfl") = 1 then delete file "Profiles\"+pfl_alias$+".pfl"
open to write 1, "Profiles\"+pfl_alias$+".pfl"
write string 1,pfl_name$ : `Player Name
write string 1,pfl_alias$ : `Player Alias
close file 1
the very last part of the code just prints the information that was written on the screen.
Loading Profiles:
Loading a profile is pretty much the same as creating one, except this time we ask the player for their alias and open to read the respective .pfl file
So below the code you have currently type the following:
REM Ask for profile name
Print "Enter Your Alias:"
Input ">: ",pfl_Alias$
REM load profile
if file exist("Profiles\"+pfl_Alias$+".pfl") = 1
open to read 1,"Profiles\"+pfl_Alias$+".pfl"
read string 1,pfl_name$ `Player Name
read string 1,pfl_alias$ `Player Alias
close file 1
endif
REM Print Information
Print "Name: "+pfl_name$
print "Alias: "+pfl_alias$
wait key
This code first asks the player to enter their alias (the profiles name), it then checks to see if something under that name exists and if it does, it loads the file in the same way that it writes the file before printing the information on the screen.
Finishing up:
Now that we have a method of creating and loading profiles we need a way for the player to choose the option they want, this version of the profile system can be completed with the following code:
REM Ask Player If they want to load or create a profile
pfl_LoadOrCreate:
Print "Type 'New' to create a new profile or 'Load' to load an existing one"
input ">:",pfl_loadorcreate$
REM Determine what the player has chosen
if pfl_loadorcreate$ = "New"
gosub SUB_pfl_NewProfile
else
if pfl_loadorcreate$ = "Load"
gosub SUB_pfl_LoadProfile
endif
endif
wait key
end
REM New Profile Subroutine
SUB_pfl_NewProfile:
REM Gather player information
Print "Please answer the following questions, as they will create the base of your profile"
Print ""
input "Please enter your name: ",pfl_name$
input "Please enter your Alias: ",pfl_alias$
Print ""
Print "Press any key to create profile"
wait key
REM Write profile info to .pfl file
if file exist("Profiles\"+pfl_alias$+".pfl") = 1 then delete file “Profiles\"+pfl_alias$+".pfl"
open to write 1,"Profiles\"+pfl_alias$+".pfl"
write string 1,pfl_name$ `Player Name
write string 1,pfl_alias$ `Player Alias
close file 1
cls
REM Print Information
Print "Name: "+pfl_name$
print "Alias: "+pfl_alias$
Return
REM Load Profile Subroutine
SUB_pfl_LoadProfile:
REM Ask for profile name
Print "Enter Your Alias:"
Input ">: ",pfl_alias$
REM load profile
if file exist("Profiles\"+pfl_alias$+".pfl") = 1
open to read 1,"Profiles\"+pfl_alias$+".pfl"
read string 1,pfl_name$ `Player Name
read string 1,pfl_alias$ `Player Alias
close file 1
endif
REM Print Information
Print "Name: "+pfl_name$
print "Alias: "+pfl_alias$
wait key
Return
This encloses both the load and create profile codes in separate subroutines, and when the player chooses which option they want, the code calls that particular subroutine.
Conclusion:
That’s it for part one, I hope that you all enjoy my first tutorial, part 2 should be done in a few weeks. Also let me know if you find any bugs in the code for this tutorial.
Until then,
Sp3ng.
Your signature has been erased by a mod because it's larger than 600x120