ID:266228
 
Im tryin to put a critical hit in my game, so that if ur speed is less than or equal to 20, then you have a 1 outta 50 chane to hit doubled ur strength, and as ur speed goes up, the likely hood of hitting a critical is better.
Here's my coding....

mob/proc/Critical(mob/M in oview(1))
if(usr.Speed <= 20)
//29// var/damage = (usr.Strength*2) rand(1,50)
if(usr.Speed <= 50)
//31// var/damage = (usr.strength*2) rand(1,30)

here are the errors i get are;
Verbs.dm:29:error: rand: expected end of statement
Verbs.dm:31:error: rand: expected end of statement

thanx to anyone for advice.
//31// var/damage = (usr.strength*2) rand(1,30)

Lets analyze this.
Say usr.strength is equal to 5

the variable damage is = 10 rand(1,30)

this it what the compiler sees. Now I assume you want to add the usr.strength*2 to rand(1,30), if so why dont you just use the addition operator?(+). The err..proper way to write it would be this

var/damage = (usr.strength*2)+rand(1,30)

You've got to realize the compiler doesnt know that you want to add the stuff, or multiply, or divide, or whatever. You've got to tell it EXACTLY what to do, or it will give you one of the many possible nasty errors.

Alathon
In response to Alathon
I dont want it to add 1 to 30 damage, thats what the probabitlity of hitting a critical is, which is 2 times the usr.Strength
In response to Robo Cop
Robo Cop wrote:
I dont want it to add 1 to 30 damage, thats what the probabitlity of hitting a critical is, which is 2 times the usr.Strength

mob/proc/Critical(mob/M in oview(1))
var/damage
if(usr.Speed <= 20 && prob(50))
damage = (usr.Strength*2)
else if(usr.Speed <= 50 && prob(30))
damage = (usr.strength*2)
In response to Spuzzum
I put it in and modified it to fit my vars, and i got it to 0 errors, and one warning, which is, variable defined but not used.....What duz that mean...and what do i need to to do fix it...heres the code...

mob/proc/Critcal(mob/M in oview(1))
if(usr.Speed <= 20 && prob(10))
usr << "YOU HIT A CRITICAL!"
var/damage = (usr.Strength*2)
In response to Robo Cop
Robo Cop wrote:
I put it in and modified it to fit my vars, and i got it to 0 errors, and one warning, which is, variable defined but not used.....What duz that mean...and what do i need to to do fix it...heres the code...

mob/proc/Critcal(mob/M in oview(1))
if(usr.Speed <= 20 && prob(10))
usr << "YOU HIT A CRITICAL!"
var/damage = (usr.Strength*2)

You need to use the damage var somewhere within the same proc

try adding:
M.Health-=damage
In response to Robo Cop
Robo Cop wrote:
I put it in and modified it to fit my vars, and i got it to 0 errors, and one warning, which is, variable defined but not used.....What duz that mean...and what do i need to to do fix it...heres the code...

mob/proc/Critcal(mob/M in oview(1))
if(usr.Speed <= 20 && prob(10))
usr << "YOU HIT A CRITICAL!"
var/damage = (usr.Strength*2)

That error means you made a variable and did nothing with it afterwards.

If you declare var/damage within a block (the indented part under the if, in this case) then that var ceases to exist when the block ends. Look again at Spuzzum's code, he declares damage before the if block, then assigns a value to damage inside the block.
In response to Nadrew
SO, heres what i have now...

mob/proc/Critical(mob/M in oview(1))
if(usr.Speed <= 20 && prob(10))
usr << "YOU HIT A CRITCAL!"
line 44 M.HP -= damage = (usr.Strength*2)

here are the errors i get...

Verbs.dm:44:error: =: expected end of statement
Verbs.dm:44:error: missing left-hand argument to =.
Verbs.dm:44:error: missing left-hand argument to =.

what does missing left-hand argument mean?




In response to Robo Cop
Robo Cop wrote:
SO, heres what i have now...

mob/proc/Critical(mob/M in oview(1))
if(usr.Speed <= 20 && prob(10))
usr << "YOU HIT A CRITCAL!"
line 44 M.HP -= damage = (usr.Strength*2)

here are the errors i get...

Verbs.dm:44:error: =: expected end of statement
Verbs.dm:44:error: missing left-hand argument to =.
Verbs.dm:44:error: missing left-hand argument to =.

what does missing left-hand argument mean?


::sigh:: I never said to take out the var/damage part now you are not defining the damage var within the same proc.