I have not had a chance to play around with this but will this weekend. I do have working code. Here is some psudo code for my question. This is slimmed down from my code as my UDT has about 20 vars.
type characterT
name as string
race as string
class as string
endtype
plrChar(25) as characterT
plrChar(1).name
plrChar(1).race
plrChar(1).class
//Save/Load Code
Maybe I need to think on this a little more but thought I would check here. I have code similar to this that works, rolls for stats, prints six stats on the screen all at once after enter is hit also a re-roll option. My question is
in the code you can see I have defined the values for player 1. my character array is for 25 characters so this should store this info in element 1 of the array. So if they do a save on the character and then come back later and decide to create another character how will the program know to store the next character in position 2 of the array and so on down the line until the character array is full? Do I have to hard code for each character? I don't think so but not sure how to do it.
Also I have seen from reading code most of the time file save and load code right there with code like this. Does it have to be that way or can I put it in a function so my character load and save code can be called from different places in the overall program?
Thanks
Dragonslayer
I am at my PC now so I will post my code. I am sure there are better and more efficient ways to do it but this works and I learned to do it with minimal posts here to figure it out. Feel free to take it if you want and feel free to comment on it. Maybe I will learn more!!!
// Practice Text RPG
// Set up a character user defined type (UDT)
type characterT
name as string
race as string
class as string
condition as string
strength as integer
intelligence as integer
dexterity as integer
constitution as integer
luck as integer
armor_class as integer
hitpoints as integer
spell_points as integer
experience_points as integer
gold as integer
level as integer
spell as integer
items as integer
endtype
//Set up a chracter array that holds every variable from the UDT to define one character.
//Create up to 25 characters
global dim plrChar(25) as characterT
// Call the set up the screen function
setUpScreen()
startGameScreen()
wait key
end
//************************************************FUNCTIONS***********************************************************
function setUpScreen()
//This function sets up the display
set display mode 800,600,32
ink rgb(0,255,0),0
set text font "courier new"
set text size 25
endfunction
function startGameScreen()
//This function shows the start game screen
set text size 35
text 200,20,"Practice Text RRPG"
set text size 25
text 255,250,"1.) Start Game"
text 255,280,"2.) Leave Game"
text 315,315,"Choice:"
set cursor 410,315
//The choices for starting or leaving the game
input choice
select choice
//This choice starts the game
case 1:
guildMenu()
endcase
//This choice ends the game
case 2:
quit()
endcase
endselect
endfunction
function guildMenu()
//This function is pretty much the main function of the game. Everything should be able to be done from the guild menu function
cls
set text size 35
text 230,20, "Adventurers Guild"
set text size 30
text 50,70,"Most everything in the game can be done from"
text 90,100,"the Adventurers Guild. Visit often!"
set text size 25
text 225,200,"1.) Create characters"
text 225,230,"2.) View Characters"
text 315,265,"Choice:"
set cursor 410,265
//The choices for the Adventurers Guild Menu
input choice
select choice
//This choice starts the game
case 1:
createCharacter()
endcase
//This choice ends the game
case 2:
viewCharacters()
endcase
endselect
endfunction
//==================================================================================================================
function createCharacter()
//Races
randomize timer()
cls
text 0,10,"Read the manual to learn more about the races and classes"
text 20,50,"Races"
text 20,51,"_____"
text 20,71,"Human"
text 20,91,"Elf"
text 20,111,"Dwarf"
text 20,131,"Hobbit"
text 20,151,"Half-elf"
text 20,171,"Half-Orc"
text 20,191,"Gnome"
//classes
text 20,329,"Classes"
text 20,330,"_______"
text 20,350,"Warrior"
text 20,370,"Paladin"
text 20,390,"Rogue"
text 20,410,"Bard"
text 20,430,"Hunter"
text 20,450,"Monk"
text 20,470,"Conjurer"
text 20,490,"Magician"
text 20,510,"Sorcerer"
text 20,530,"Wizard"
//Character Setup
set cursor 300,50
input "Name:",plrChar(1).name
set cursor 300,70
input "Race:",plrChar(1).race
set cursor 300,90
input "Class:",plrChar(1).class
roll:
plrChar(1).strength = rnd(25)+1
set cursor 300,110
print "Strength(ST):",plrChar(1).strength
plrChar(1).intelligence = rnd(25)+1
set cursor 300,130
print "Intelligence(IQ):",plrChar(1).intelligence
plrChar(1).dexterity = rnd(25)+1
set cursor 300,150
print "Dexterity(DX):",plrChar(1).dexterity
plrChar(1).constitution = rnd(25)+1
set cursor 300,170
print "Constitution(CN):",plrChar(1).constitution
plrChar(1).luck = rnd(25)+1
set cursor 300,190
print "Luck(CN):",plrChar(1).luck
plrChar(1).hitpoints = rnd(30)+1
set cursor 300,210
print "hitpoints(CN):",plrChar(1).hitpoints
set cursor 260,250
input "Do you want to re-eoll?:y/n ", a$
if a$ = "y"
cls
gosub roll:
else a$ = "n"
wait key
ENDIF
endfunction
//==================================================================================================================
function viewCharacters()
cls
text 200,200, "View character function"
endfunction
//==================================================================================================================
function quit()
cls
set text size 35
text 200,20,"Practice Text RRPG"
text 200,200, "Thanks for playing.........."
sleep 2000
end
ENDFUNCTION