ID:269712
 
This is the code for my battle system.
    proc
Battle(attacker,defender)
var/damage
var/otherhit
var/otherdamage
sleep(10)
var/hit = rand(1,(attacker:attack[1] - defender:agility))
if(hit <= 1)
if(defender:defence > attacker:strength[1])
var/chance = rand(0,4)
if(chance == 1)
damage = rand(1,attacker:strength[1])
usr << "[defender] did [otherdamage] to you"
usr << "Your strength is to little to breach the defence"
else
damage = rand(1,(attacker:strength[1] - defender:defence))
usr << "You do [damage] to [defender]"
defender:health -= damage
else
usr << "You have missed"
ChkHealth(attacker,defender)
if(ChkHealth())
return
sleep(10)
otherhit = rand(1,(defender:attack - attacker:agility[1]))
if(otherhit <= 1)
if(attacker:defence[1] > defender:strength)
var/chance = rand(0,4)
if(chance == 1)
otherdamage = rand(1,defender:strength)
usr << "[defender] did [otherdamage] to you"
else
usr << "The enemys strength is to little to breach your defence"
else
otherdamage = rand(1,(defender:attack - attacker:defence[1]))
usr << "[defender] did [otherdamage] to you"
attacker:health -= otherdamage
else
usr << "[defender] has missed"
ChkHealth(attacker,defender)
if(ChkHealth())
return
Battle(attacker,defender)
ChkHealth(var/A,var/D)
if(A:health <= 0)
A << "[A] has died at the hands of [D]"
A:health = A:maxhealth[1]
A:loc = locate(1,1,1)
return 1
if(D:health <= 0)
A << "You have killed [D]"
del(D)
return 1

I have already defined the varibles in there in another piece of code. When I run this each time I loop though the battle system it comes up with this error:

runtime error: Cannot read null.health
proc name: ChkHealth (/mob/proc/ChkHealth)
usr: ADT_CLONE (/mob/player)
src: Rat (/mob/Rat)
call stack:
Rat (/mob/Rat): ChkHealth(null, null)
Rat (/mob/Rat): Battle(ADT_CLONE (/mob/player), Rat (/mob/Rat))
Rat (/mob/Rat): Attack()

Could someone please help me.[EDIT] this is how I run the proc:
    verb
Attack()
set src in oview(1)
usr << "[usr],[src]"
Battle(usr,src)
This battle system works along with the health check though the errors always come up.
ADT_CLONE wrote:
This is the code for my battle system.
>   proc
> ChkHealth(var/A,var/D)
> if(A:health <= 0)
> A << "[A] has died at the hands of [D]"
> A:health = A:maxhealth[1]
> A:loc = locate(1,1,1)
> return 1
> if(D:health <= 0)
> A << "You have killed [D]"
> del(D)
> return 1
>


This is a problem. DON'T use the : operator. You could have just as easily accessed the variables normally:

        ChkHealth(var/mob/A,var/mob/D)
// now use A.health in place of A:health


This applies to your Battle proc as well. You should not rely on empty types and the : operator. That's about as bad as the fact that...


USR ABUSE!!! How does it go? "Ungh, no put usr in proc," or something like that. Long, long ago, something called src was invented. Use that instead of usr.


In addition, you may want to look into your spelling errors. "Your strength is to little to breach the defence" --- I won't bother with defence's spelling, as that varies by location. But the first "to" should be "too" .... Periods are nice at the end of sentences.

Hiead
In response to Hiead
After I did all you said it still has the same errors.
In response to Hiead
Using src in that proc would be the rat, not the player, so usr is neccesary. You should remove attacker and defender and just use the src and usr variable. And your error is most likely from your empty check health proc, this "ChkHealth()". With no variables there, they would become null and then error. Just remove the A and B variable there as well, and make use of the src and usr variable. As well, the proc above the if statement is not doing anything, and you should just erase it since you already have it in the if statement.
In response to ADT_CLONE
Yeah now its working. Thanks.
In response to Kija
Bad bad bad bad bad bad bad bad bad BAD!

No put usr in proc! Keep the arguments! For the love of the Great Spaghetti Monster!
In response to Kija
Kija wrote:
Using src in that proc would be the rat, not the player, so usr is neccesary. You should remove attacker and defender and just use the src and usr variable.

Avast, m'lad! Yer off in a fog an' steerin' yer mates into the rocks. Ain't no call to be usin' usr outside of a verb, mate. Usin' it improper is fer squiffies. The only way through's to tell yer proc what's what by sendin' it more directions, not tossin' the compass and pretendin' you know which way is north.

Cap'n Clone has the right tools already. He just needs to use 'em.

And your error is most likely from your empty check health proc, this "ChkHealth()". With no variables there, they would become null and then error.

Aye, he fouled that proc asure. It needs but one argument, that bein' the attacker, and the defender be known as src. An' fer abusin' the colon operator he should feel a taste o' the lash.

Just remove the A and B variable there as well, and make use of the src and usr variable.

Garn! Belay that sprog-patter. When ya sails yer own boat you can sail off blind all you want, but don't go tellin' someone to drop his sextant. That usr ain't no guide in a proc. Steer by the stars you can trust.

As well, the proc above the if statement is not doing anything, and you should just erase it since you already have it in the if statement.

Methinks the one he has afore it should go inside the if, an' the one inside he should dump out to sea.

Cap'n Lummox JR
In response to Lummox JR
Lummox JR wrote:
Cap'n Lummox JR

Perhaps...Lummox has upgraded into something new? Heh, that's got to be the hardest-for-me-to-read message you've ever posted.

['DIT]
Jus' noticed it be talk like a pirate day. Arr....
[/'DIT]

Hiead
In response to Lummox JR
/me wonders if Lummox has a pirate translater, arrgh.
In response to Kalzar
Kalzar wrote:
/me wonders if Lummox has a pirate translater, arrgh.

First time is free. After that it'll cost ya.

Avast, m'lad! Yer off in a fog an' steerin' yer mates into the rocks.

You're in the wrong, and you're leading others in the wrong direction.

Ain't no call to be usin' usr outside of a verb, mate.

Don't use usr outside of verbs.

The only way through's to tell yer proc what's what by sendin' it more directions, not tossin' the compass and pretendin' you know which way is north.

Use paramaters and pass arguments, don't just use things(src, usr) and assume you know what they reference.

Aye, he fouled that proc asure. It needs but one argument, that bein' the attacker, and the defender be known as src. An' fer abusin' the colon operator he should feel a taste o' the lash.

Yes, he messed up that proc. It only needs one argument, for the attacker, since src will reference the defender. And you should be tortured for your abuse of the colon ( : ) operator.

When ya sails yer own boat you can sail off blind all you want, but don't go tellin' someone to drop his sextant. That usr ain't no guide in a proc. Steer by the stars you can trust.

You can make bad mistakes for yourself, but don't impress bad practices upon others. Don't use usr in a proc.

Methinks the one he has afore it should go inside the if, an' the one inside he should dump out to sea.

I think (Lummox's opinion is the best way to go, usually) that he should move the first call to go inside the if, and the one already there should be removed completely.

Firs' Mate Hiead
In response to Lummox JR
You could use a variable for usr, but by making that variable from usr, you are already using usr. And there is no reason to make a variable for something you already have. Usr does work and it is not bad to use it.
In response to Kija
Kija....it IS bad. usr doesn't always have a value. Sometimes usr does have a value, but not the one you'd expect. In procs that will not be called directly, it is a no-no. Some procs that are generally called directly(though not always) are Click and verbs. But since it is possible to call those without the player directly doing so, it is almost always better to use src or arguments.

As to why he gets errors, I've read a bit more into his code, and it's probably because he calls that Chk proc with no args, and the proc has no tests to make sure the attacker and defender vars have values.

Hiead
In response to Kija
Kija wrote:
Usr does work and it is not bad to use it.

Arg! I see an angry sea monster with a fiery breath ahead! Batten down the hatches and dump all ye sqalliwags dun need. Arg... Me thinks I'm really bad this...

['dit] It appears it ate ye before I could warn ye of yur bad sea faring. [/Edit]
In response to Hiead
Yes, we all know about the if statement, people have said it plenty of times. But if usr was null, then setting the variable for usr would be null too.
In response to Kija
Kija wrote:
Yes, we all know about the if statement, people have said it plenty of times. But if usr was null, then setting the variable for usr would be null too.

When have I said
var/mob/wtf = usr

???

Hiead
In response to Kija
Kija wrote:
You could use a variable for usr, but by making that variable from usr, you are already using usr.

Arr, ye be tyin' gimpy knots again, me swabbie. Ya don't take yer bearings from usr, says I. Riggin' a var from usr ain't no better'n just havin' usr i'self. T'ain't what I said.

And there is no reason to make a variable for something you already have.

Aye, but from usr ya got nothin', so ya don't go makin' a var from it! Ya takes the readin's from where ya calls the proc, an' sends it over so the navigator knows whatfor. I din't say copy the bad charts. I says ya has to get it right the first time.

Usr does work and it is not bad to use it.

Hang up yer brig on a sandbar if ya wants, but I says again ya don't go passin' yer sproggy bilge onto honest jacks what have a chance to rake in the booty. If ya din't get yer bearings true, there's no trustin' 'em, savvy? After usr leaves the verb ya don't know who passed it on or how it got to ya, or if yer messenger was a rum-pated lout what picked it up from anywhere. If ya needs more'n src, then send it sure or do without.

Cap'n Lummox JR
In response to Kija
Kija wrote:
Yes, we all know about the if statement, people have said it plenty of times. But if usr was null, then setting the variable for usr would be null too.

No lyin', mate! 'S'why that ain't what ya does! Ya has to send it over proper, not take it from usr when it gets there.

Cap'n Lummox JR
In response to Lummox JR
If that was the case, then would not his usr<< messages not be working? Yet he has made no claim they were broken, so it can easily be assumed that usr is you, for it is. Now, if for some reason it was not, then possibly you could, but if usr does work, then there is no reason to create another variable for it; that would just be a waste of space. And if you are going to use such variables, you might as well not make it a mob proc.
In response to Kija
Kija wrote:
If that was the case, then would not his usr<< messages not be working? Yet he has made no claim they were broken, so it can easily be assumed that usr is you, for it is.

Aye, me bucko, if ye assumes the sun always shines an' the wind's always from the north, an' the sutler ain't cheatin' ya on yer stock. Just 'cause it works once when ya trusts the wrong swab, don't mean it'll work again! If ya leans on the busted railin' and falls into the drink, ain't no one to cry fer ya but yerself.

Now, if for some reason it was not, then possibly you could, but if usr does work, then there is no reason to create another variable for it; that would just be a waste of space.

Blimey, maps and compass be wasted space too, then. Ye takes what ya needs so ya don't get lost. Don't just go trustin' the first sod to say "Thataway".

And if you are going to use such variables, you might as well not make it a mob proc.

Whyfor, m'lad? Tho' usr be iffy, src be as true as the stars i'the sky.

Cap'n Lummox JR
Page: 1 2