Here's one way to do it, and it doesn't decrease your level if you lost XP from death either. Loop through like so, but of course your Current_XP and Current_Level and Maximum_Levels variables will be different. I hardcoded them in this example on the first three lines. So you'd want to remove those lines and make these like global variables or something. :
define procedure <experience>
set numeric <Current_Level; 1>
set numeric <Maximum_Levels; 20>
set numeric <Current_XP; 12345>
set numeric <Next_Level; %Current_Level% + 1>
set numeric <XP_To_Next_Level; 0>
set numeric <Leveled_Up_This_Time; 0>
for <tempLevelPointer; 1; %Maximum_Levels%; 1> {
if ( %tempLevelPointer% = %Next_Level% ) then {
msg <...checking for level up condition.>
set numeric <bluetooth; %Next_Level% * 1000>
set numeric <greentooth; %bluetooth% / 2>
set numeric <XP_To_Next_Level; %bluetooth% + %greentooth%>
set numeric <XP_Difference; %XP_To_Next_Level% - %Current_XP%>
if ( %XP_Difference% <= 0 ) and ( %Current_Level% <> %Maximum_Levels% ) then {
msg <You can level up to |b%Next_Level%|xb!.... (run the level up procedure or prompt the player here for new spells, abilities, etc.)>
inc <Current_Level; 1>
inc <Next_Level; 1>
set numeric <Leveled_Up_This_Time; 1>
}
}
}
if ( %Leveled_Up_This_Time% = 1 ) then set string <myDisplayString; Sorry but you can't level up anymore right now.> else set string <myDisplayString; Sorry, you can't level up.>
if ( %Current_Level% <> %Maximum_Levels% ) then msg <#myDisplayString# You need %XP_Difference% more XP to make it to Level %Next_Level%>
if ( %Current_Level% = %Maximum_Levels% ) then msg <You are already at the highest level allowed in this game. You are level %Current_Level%.>
end define
Of courst this only accounts for 20 levels, and I'm not sure on the math formula, but you'll want some kind of math formula like this to make your job easier. i.e. "XP Per Level" = (level * 1000) + ((level * 1000) / 2)
Also, might want to keep an eye on how big those numbers are you're dealing with. I'd personally go with a smaller numbered XP system myself to allow for really high levels, and adjust the monster kill XP reward down a bit or level cap it so the lower level stuff doesn't give you an unfair XP gain in a system like this. Smaller numbers will work out better (IMO), and the reason why is you don't want huge numbers floating around in memory or bad things *might* happen (i.e. program crash).
Here is a full .ASL file for you. Just talk to the trainer and answer yes and he'll level you up.
' "test XP game"
' Created with QDK Pro 3.52
define game <test XP game>
asl-version <350>
gametype singleplayer
start <Training Room>
game author <myAuthorName>
game info <Created with QDK Pro 3.52>
startscript do <initialize>
end define
define synonyms
end define
define room <Training Room>
alias <Training Center>
prefix <the>
look <This is the training center.>
define object <Warrior Trainer>
alias <Trainer>
alt <warrior trainer; guild leader>
look <This is the warrior trainer.>
speak choose <trainer>
examine <The warrior trainer stands ready to help you train to the next level, if you're able. Just talk to him.>
prefix <a>
end define
end define
define procedure <experience>
set numeric <Next_Level; %Current_Level% + 1>
set numeric <XP_To_Next_Level; 0>
set numeric <Leveled_Up_This_Time; 0>
for <tempLevelPointer; 1; %Maximum_Levels%; 1> {
if ( %tempLevelPointer% = %Next_Level% ) then {
msg <...checking for level up condition.>
set numeric <bluetooth; %Next_Level% * 1000>
set numeric <greentooth; %bluetooth% / 2>
set numeric <XP_To_Next_Level; %bluetooth% + %greentooth%>
set numeric <XP_Difference; %XP_To_Next_Level% - %Current_XP%>
if ( %XP_Difference% <= 0 ) and ( %Current_Level% <> %Maximum_Levels% ) then {
msg <You can level up to |b%Next_Level%|xb!.... (run the level up procedure or prompt the player here for new spells, abilities, etc.)>
inc <Current_Level; 1>
inc <Next_Level; 1>
set numeric <Leveled_Up_This_Time; 1>
}
}
}
if ( %Leveled_Up_This_Time% = 1 ) then set string <myDisplayString; Sorry but you can't level up anymore right now.> else set string <myDisplayString; Sorry, you can't level up.>
if ( %Current_Level% <> %Maximum_Levels% ) then msg <#myDisplayString# You need %XP_Difference% more XP to make it to Level %Next_Level%>
if ( %Current_Level% = %Maximum_Levels% ) then msg <You are already at the highest level allowed in this game. You are level %Current_Level%.>
end define
define procedure <initialize>
set numeric <Current_XP; 12345>
set numeric <Current_Level; 1>
set numeric <Maximum_Levels; 20>
end define
define text <intro>
end define
define text <win>
end define
define text <lose>
end define
define selection <trainer>
info <"Up for some training today?" the trainer asks you.>
choice <Yes> do <experience>
choice <No> msg <The trainer says,"Okay, friend. Good luck and safe hunting!">
end define
The point where it says "run the level up procedure or prompt the player here for new spells, abilities, etc" .... this is where I would put the NPC prompt to ask if the player wants to purchase training to level up. If the player can not afford it or declines, then that's the end of the check and it stops right there. If the player accepts, the loop goes to the next level check automatically, etc.