Page 1 of 1

EXP

Posted: Thu May 14, 2009 4:50 pm
by floogle11
Ummm.. Hi in the making of my game I can't figure out a faster way to make if statments for my levels like you are level 1 um I have about 80 If statments just for that. Does anybody know an easier way?

Posted: Thu May 14, 2009 6:09 pm
by MystikShadows
it would probably help if you posted some code so we can situate ourself as to what you want to do...

The method will change if you want to increase at regular intervales (every 50 points for example) or if you have variable set values.

For example: if you want to increase every 100 points. Somthing like this would work

Code: Select all

IF CurretnScore/100 = INT(CurrentScore/100) THEN
   CurrentLevel = CurrentScore / 100
END IF
Just change the 100 to the mumber of points you want the interval to be fore.

Hope this helps.

Thanks

Posted: Thu May 14, 2009 6:24 pm
by floogle11
Thanks but when it is current score do I just change to EXP or the variable?


And I was doing somthing like this...
Code:
LET EXP = 0
LET LEVEL = 1
IF EXP = 100 THEN LET LEVEL = LEVEL + 1
IF EXP = 300 THEN LET LEVEL = LEVEL + 1
And so on...

Posted: Thu May 14, 2009 6:51 pm
by MystikShadows
LET EXP = 0
LET LEVEL = 1
IF EXP = 100 THEN LET LEVEL = LEVEL + 1
IF EXP = 300 THEN LET LEVEL = LEVEL + 1

if they are every 200 points like your example here, then you can just divide EXP by 200

LEVEL = (EXP / 200) + 100

shouold do the same as all your IF statements

Posted: Thu May 14, 2009 7:08 pm
by bongomeno
for you, i would suggest something like this

Code: Select all

let level=1
let nextlevlat=5
let score=0

do

rem all your game stuff.......

if score>=nextlevelat then
let level=level+1
let nextlevelat=int(nextlevelat/2)+level
end if

loop
also, if you dont want to use 80 if statements, i suggest using 'select case'
example (your code modified):

Code: Select all

let level=1
let xp=0

do

rem all your game stuff....

let xp=xp+1

select case xp

case 50
print "level up!"
let level=level+1
let xp=100

case 200
print "level up!"
let level=level+1
let xp=350

case 350
print "level up!"
let level=level+1
let xp=550

case 550
print "you win!"
end

end select

loop

and 1 more thing, you used exp as a variable, that is not valid because it as a function.

good luck with your new game!

Thanks

Posted: Thu May 14, 2009 7:10 pm
by floogle11
Thanks I have got it now. That saved me from like 15 exra minutes from programming. :D

Does

Posted: Thu May 14, 2009 7:19 pm
by floogle11
Does this work?:
HIT = 1
LET Longsword$ = "no"
IF Longsword$ = "yes" THEN LET HIT = HIT + 10
IF Longsword$ = "no" THEN LET HIT = HIT * 0
INPUT "You wanna buy a longsword?"; yes$
IF yes$ = "yes" OR yes$ = "Yes" OR yes$ = "YES" THEN LET Longsword = Longsword - "no" + "yes"

Posted: Thu May 14, 2009 11:22 pm
by burger2227
You cannot SUBTRACT from strings. You can only Add them.

Use MID$ or RIGHT$ or LEFT$ to use parts of a string.
IF yes$ = "yes" OR yes$ = "Yes" OR yes$ = "YES" THEN LET Longsword = Longsword - "no" + "yes"
I this case, your IF statement only needs modified:

Code: Select all

IF UCASE$(yes$) = "YES" THEN 
   Longsword$ = "yes"
ELSE : Longsword$ = "no"
END IF
Forget about LET! It is never necessary.

Ted

thanks

Posted: Sat May 16, 2009 1:42 pm
by floogle11
okay i think thats all my quetions so far

how i did it in DSQ

Posted: Sun Aug 09, 2009 4:14 pm
by coma8coma1
I'm assuming you'er making an RPG? Me too!

My level-up and level checking code goes something like this... Both of these first two little chunks of code exist in my "Battle" routine where all combat takes place. The First part is the code that run s when you WIN the fight. Note the part where xp& is checked against the next levels experience breakpoint which is stored in a single dimension array called Breakpoint&() with enough elements to store the breakpoints for all experience levels. Also note that I've made both "gp&" gold and "xp&" experience long intergers because I want them to top out at 9,999,999 like some old Nintendo games do, and an regular integer wasn't big enough. Also note that when your level reaches the upperbound of the braekpoint array (ie: you've maxed out your levels) you cannot anylonger level-up.

Next is the sub routine, also in my Battle() sub, which actually adjusts the player's experience level and displays the fact on screen. "LevelUp"

Finally, I've copy and pasted a chunk of code from my "UpdateStats" routine which updates the players stats any time it's called. Among other things, it looks at a two-dimensional array which stores all of the vital level-specific stats for the player. One dimension is the experience level, while the other dimension is the statistics such as maximum hitpoints, maximum magic points, base strength, and base chance to hit. The part you're looking for is the last four lines there. See, I just used a simple array, which saves the trouble of a nightmare block of IF...THENs or a ginormous SELECT CASE.

Code: Select all

YouWin:
 Draw.Map
 gp& = gp& + mgp
 xp& = xp& + mxp
 IF gp& > 9999999 THEN gp& = 9999999
 IF xp& > 9999999 THEN xp& = 9999999
 abat = abat + "^|080000You have defeated the " + mon$ + "!"
 a = abat: Text
 abat = abat + "^@Your|137000 experience@ increases by|137000" + STR$(mxp) ' + "@."
 a = abat: Text
 abat = abat + "^@Your|154000 gold@ increases by|154000" + STR$(mgp) ' + "@."
 IF lvl <> UBOUND(Breakpoint&) THEN                 '*
  IF xp& >= Breakpoint&(lvl + 1) THEN abat = abat + "\" + CHR$(13)
 END IF                                             '
 a = abat: Text
ExitBattle:
 UpdateTherm
 IF lvl <UBOUND> 9999999 THEN gp& = 9999999
 IF xp& > 9999999 THEN xp& = 9999999
 ac% = 0
 absorb% = 100
 rfire% = 100
 rcold% = 100
 relec% = 100
 rchem% = 100
 hpmax = Level%(lvl, 0)     'these four lines
 mpmax = Level%(lvl, 1)     'check the Level% array
 str% = Level%(lvl, 2)     'for current stats
 tohit% = Level%(lvl, 3)
I hope that helps someone somewhere. You'd need to dimension arrays and junk to run this code. It's ust too much to type out so I just copied and pasted it right outta my BAS file. any Q's post here. k, later! -come8coma1

Posted: Sun Aug 09, 2009 4:15 pm
by coma8coma1
hmm, i guess i'm only allowed to post one piece of code at a time?

here's the other two i promised

Code: Select all

LevelUp:
 GetA
 abat = MID$(abat, 1, LEN(abat) - 1) + CHR$(34) + "^Your level has increased!!": a = abat: Text
 oldhpmax = hpmax
 oldmpmax = mpmax
 oldlvl = lvl
 lvl = 1
 DO
  lvl = lvl + 1
  IF lvl = UBOUND(Breakpoint&) THEN EXIT DO
 LOOP UNTIL Breakpoint&(lvl + 1) > xp&
 abat = abat + "@^You are now level" + STR$(lvl) + ".": a = abat: Text
 UpdateStats
 abat = abat + "^Your Hit Points increase by" + STR$((hpmax - oldhpmax)) + ".": a = abat: Text
 IF mpmax - oldmpmax > 0 THEN abat = abat + "^Your Magic Points increase by" + STR$((mpmax - oldmpmax)) + ".": a = abat: Text
 IF Level%(lvl, 2) > Level%(oldlvl, 2) THEN abat = abat + "^Your Strength increases by" + STR$(Level%(lvl, 2) - Level%(oldlvl, 2)) + ".": a = abat: Text
 IF Level%(lvl, 3) > Level%(oldlvl, 3) THEN abat = abat + "^Your Chance to Hit increases by" + STR$(Level%(lvl, 3) - Level%(oldlvl, 3)) + ".": a = abat: Text
 RETURN

Posted: Sun Aug 09, 2009 4:15 pm
by coma8coma1
and finally


'just some code from the UpdateStats routine:

Code: Select all

 IF gp& > 9999999 THEN gp& = 9999999
 IF xp& > 9999999 THEN xp& = 9999999
 ac% = 0
 absorb% = 100
 rfire% = 100
 rcold% = 100
 relec% = 100
 rchem% = 100
 hpmax = Level%(lvl, 0)     'these four lines
 mpmax = Level%(lvl, 1)     'check the Level% array
 str% = Level%(lvl, 2)     'for current stats
 tohit% = Level%(lvl, 3)