ID:147882
 
When I start a battle, it goes into a system which is right, but when I hit Run, it attacks, when i hit Item, it still attacks, when i hit anything, it attacks, its as if my attack var is the only thing it uses, please help, heres the code:
mob
proc
Battle()
if(usr.poisoned == 1)
usr << "You recieve damage from poison!"
sleep(10)
usr.hp /= 25
usr.hp = round(usr.hp)
if(usr.mem == 0)
usr.memattack = usr.attack
usr.memdefense = usr.defense
usr.memintelligence = usr.intelligence
usr.memagility = usr.agility
usr.memluck = usr.luck
usr.mem = 1
input("You encountered [src]! Command?","Battle!") in list("Attack","Spell","Item","Defend","Run")
if("Attack")
Attack()
else if("Spell")
Spell()
else if("Item")
Item()
else if("Defend")
Defend()
else if("Run")
Run()
First off don't use usr in procs!

input("You encountered [src]! Command?","Battle!") in list("Attack","Spell","Item","Defend","Run")

Input returns the item selected from the list which you definantly want to store in a variable.

if("Attack")
Attack()

"Attack" is non-zero so it's always true and will always execute Attack(). You probably want to compare it to something, most likely the result of the input list.
In response to Theodis
Well, how do i do that? (im not that great at coding yet)
In response to Metroid
Just put that input in a switch:

switch(input()in list)

Then indent all the "ifs" a tab.
No put usr in proc. Ungh.

Lummox JR
In response to Lummox JR
What a useful post, considering that Theodis pointed that out hours ago, and in a slightly more understandable fashion.

Metroid, look up input() in the DM reference. By default, it gets the input from usr. Since you're using input() in a proc, you need to make it get the input from src instead. So even if you already changed all your usr's to src's, there's that one hiding in there that you might not have caught.
In response to Metroid
Well, how do i do that? (im not that great at coding yet)

I don't know exactly how you are calling the Battle() proc but you probably want to pass in the mob the monster is attacking.

ie:
Battle(mob/Player)

when you call it make sure to pass in the player. How you do this depends on where you're calling the Battle proc. In your battle proc replace all the usr's with Player. Also make sure that you only pass in mob's with clients since if you pass in a mob not connected to a client you'll get a bad client run-time error.

To store the result of the input define a variable
var/selection

then have the input command return it's selection into the selection variable

selection = input("You encountered [src]! Command?","Battle!") in list("Attack","Spell","Item","Defend","Run")

Then instead of just having if("Attack") compare Attack to the result of the input

if(selection == "Attack")

You need to do the same for the rest of the comparisons. But it might be good to use a switch statement instead so go look that up in the reference.

You are apparently missing some of the fundamentals of programming it might be best not to do a game yet. You should probably go through the tutorials, the guide, and read through the blue book and get a better programming foundation before attempting to make a game.
In response to OneFishDown
OneFishDown wrote:
What a useful post, considering that Theodis pointed that out hours ago, and in a slightly more understandable fashion.

I looked in his post for any mention of usr, but somehow I completely missed that. Chalk it up to having a 15 lb. cat on my lap and being distracted by the difficulty of typing, I guess. Doh!

Lummox JR
I got other problems now too.
Whenever I end a battle(I got the battle thing working, in a way) I get these runtime errors:
runtime error: Cannot read null.jobexpreq
proc name: checkjoblevel (/mob/proc/checkjoblevel)
source file: Level.dm,10
usr: Metroid (/mob/blue)
src: Slime (/mob/monster/Slime)
call stack:
Slime (/mob/monster/Slime): checkjoblevel(null)
Slime (/mob/monster/Slime): Deathcheck()
Slime (/mob/monster/Slime): Attack()
Slime (/mob/monster/Slime): Battle()
Slime (/mob/monster/Slime): Bumped(Metroid (/mob/blue))
Metroid (/mob/blue): Bump(Slime (/mob/monster/Slime))
runtime error: Cannot read null.expreq
proc name: checklevel (/mob/proc/checklevel)
source file: Level.dm,4
usr: Metroid (/mob/blue)
src: Slime (/mob/monster/Slime)
call stack:
Slime (/mob/monster/Slime): checklevel(null)
Slime (/mob/monster/Slime): Deathcheck()
Slime (/mob/monster/Slime): Attack()
Slime (/mob/monster/Slime): Battle()
Slime (/mob/monster/Slime): Bumped(Metroid (/mob/blue))
Metroid (/mob/blue): Bump(Slime (/mob/monster/Slime))

Here's my Deathcheck var
Deathcheck()
if(src.hp <= 0)
usr << "You have killed the [src]!"
sleep(10)
usr << "You recieve [src.expreward] exp and [src.gold] gold!"
if(src.jobexpreward >= 1)
usr << "<font color = blue><b>You recieve [src.jobexpreward] job exp!"
usr.jobexp += jobexpreward
usr.attack = usr.memattack
usr.defense = usr.memdefense
usr.intelligence = usr.memintelligence
usr.agility = usr.memagility
usr.luck = usr.memluck
if(usr.attackdoubled == 1)
usr.attackdoubled = 0
if(usr.defensedoubled == 1)
usr.defensedoubled = 0
if(usr.intelligencedoubled == 1)
usr.intelligencedoubled = 0
if(usr.luckdoubled == 1)
usr.luckdoubled = 0
if(usr.agilitydoubled == 1)
usr.agilitydoubled = 0
usr.exp += src.expreward
usr.gold += src.gold
usr.islocked = 0
usr.battle = 0
usr.lib = 0
checkjoblevel()
checklevel()
usr.mem = 0
if(usr.boss1 == 1)
usr.boss1 = 0
usr.boss1defeated = 1
usr.loc = locate(16,9,1)
del src
if(usr.hp <= 0)
usr << "<b><font color = blue>You died! The [src] runs away with half your gold!"
usr.gold /= 2
usr.gold = round(usr.gold)
src.gold *= 2
usr.islocked = 0
src.islocked = 0
usr.hp = usr.maxhp
src.hp = src.maxhp
src.mp = src.maxmp
usr.lefttown = 0
usr.battle = 0
src.battle = 0
usr.lib = 0
usr.poisoned = 0
usr.diseased = 0
usr.x = usr.innx
usr.y = usr.inny
usr.z = usr.innz
usr.attack = usr.memattack
usr.defense = usr.memdefense
usr.intelligence = usr.memintelligence
usr.agility = usr.memagility
usr.luck = usr.memluck
if(usr.attackdoubled == 1)
usr.attackdoubled = 0
if(usr.defensedoubled == 1)
usr.defensedoubled = 0
if(usr.intelligencedoubled == 1)
usr.intelligencedoubled = 0
if(usr.luckdoubled == 1)
usr.luckdoubled = 0
if(usr.agilitydoubled == 1)
usr.agilitydoubled = 0
usr.mem = 0

Yes i know about the dont use usr in a proc, and im fixing that, but thats not the reason, i still get those runtime errors
In response to Metroid
The problem is pretty simple. The problem proc is checkjoblevel(). Looking at
Slime (/mob/monster/Slime): checkjoblevel(null)
Slime (/mob/monster/Slime): Deathcheck()
Slime (/mob/monster/Slime): Attack()
Slime (/mob/monster/Slime): Battle()
Slime (/mob/monster/Slime): Bumped(Metroid (/mob/blue))
Metroid (/mob/blue): Bump(Slime (/mob/monster/Slime))
you can see that checkjoblevel is being passed null(ie nothing), when it requires something to be passed.
In response to Metroid
Metroid wrote:
Yes i know about the dont use usr in a proc, and im fixing that, but thats not the reason, i still get those runtime errors

Until you've actually fixed it, you can't count on that not being the reason for your errors. The reason I always tell someone in this position to fix the usr issue first is that it can cause a lot of hidden bugs, or it can often be the cause of whatever bugs they are seeing. Even if it's assuredly not, the correct fix to the bug may not look correct if implementing it exposes one of the bugs caused by abusing usr.

Debugging rule of thumb: Fix the holes you know about first, then go after the ones you don't.

Lummox JR