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()
ID:147882
Oct 17 2003, 11:34 am
|
|
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:
|
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. |
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() 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) |
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 |
Input returns the item selected from the list which you definantly want to store in a variable.
"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.