EXP

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

EXP

Post 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?
Go to my Qbsite its: Trueqb.webs.com
Or if you play nazi zombies go to www.Nazizombys.com and register for cheats, hints, and strategys.
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post 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.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

Thanks

Post 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...
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post 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
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

Post 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!
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

Thanks

Post by floogle11 »

Thanks I have got it now. That saved me from like 15 exra minutes from programming. :D
Go to my Qbsite its: Trueqb.webs.com
Or if you play nazi zombies go to www.Nazizombys.com and register for cheats, hints, and strategys.
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

Does

Post 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"
Go to my Qbsite its: Trueqb.webs.com
Or if you play nazi zombies go to www.Nazizombys.com and register for cheats, hints, and strategys.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

thanks

Post by floogle11 »

okay i think thats all my quetions so far
Go to my Qbsite its: Trueqb.webs.com
Or if you play nazi zombies go to www.Nazizombys.com and register for cheats, hints, and strategys.
User avatar
coma8coma1
Veteran
Posts: 100
Joined: Sat Dec 08, 2007 5:29 pm
Location: Maryland, USA

how i did it in DSQ

Post 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
User avatar
coma8coma1
Veteran
Posts: 100
Joined: Sat Dec 08, 2007 5:29 pm
Location: Maryland, USA

Post 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
User avatar
coma8coma1
Veteran
Posts: 100
Joined: Sat Dec 08, 2007 5:29 pm
Location: Maryland, USA

Post 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)
Post Reply