ID:144385
 
Code:
mob
verb
Cast_Ice_On_Weapon()
if(usr.mana <= 10)
if(usr.weapon_equipped == 1)
if(usr.ecasted == 1)
usr.weaponpower+=20
usr.overlays += 'Ice.dmi'
usr.mana -= 10
usr.ecasted = 1
else
usr << " You do not have enough mana!"
else
usr << " You do not have a weapon equipped!"
else
usr << " You already have an elemen


Problem description:
It says that the second else clause has no preceding if statement, which I clearly made three if's and three elses. Anyone see the problem? I might have been able to see it if I wasn't a bit tired at the moment, but I checked for like 10 minutes, I know it's a bit noobish but I can't find it.
You have the elses backwards.
In response to Popisfizzy
What do you mean? v.v
mob
verb
Cast_Ice_On_Weapon()
if(usr.mana <= 10)
if(usr.weapon_equipped == 1)
if(usr.ecasted == 1)
usr.weaponpower+=20
usr.overlays += 'Ice.dmi'
usr.mana -= 10
usr.ecasted = 1

/*you need to add the elses like this:
else *blah* else goes here first
else *blah* I hope you are beggining to understand >_>
else


In response to Renparo
Meaning you turn the operators around:

You have
if
   if
      if

else
   else
      else
The last two else falls under the first two else.. you want if() to be in desending order and else in ascending order:

if
   if
      if

      else
   else
else


- GhostAnime
In response to Avren
Oh yeah! Sorry about that I dozed off for a moment, I was thinking as if they were all one, sorry about that. Got it done >.> Thanks.
In response to GhostAnime
mob
verb
Cast_Ice_On_Weapon()
if(usr.mana <=10)
usr.mana -= 10
else
usr << " You do not have enough mana!"
if(usr.weapon_equipped == 1)
usr.weaponpower+=20
else
usr << " You do not have a weapon equipped!"
if(usr.ecasted == 0)
usr.weaponpower+=20
usr.overlays += 'Ice.dmi'
usr.ecasted = 1
else
usr << " You already have an element casted on your weapon!"


Problem Description number 2:
Well if I don't have the weapon equipped I can still cast the spell. It always says You do not have enough mana! Even if I have 100 and it never subtracts even if the overlay appears on top of it. It actually says all three "elses" every time, even if all the requirments are kept. v.v I'm going to bed after this is fixed, see if a good nights sleep will help.
In response to Renparo
mob
verb
Cast_Ice_On_Weapon()
if(usr.mana >=10) /*that's because your symbol was backwards, you were
basically saying that if usr.mana is smaller than
or equal to, to take away mana!*/

usr.mana -= 10
else
usr << " You do not have enough mana!"
if(usr.weapon_equipped == 1)
usr.weaponpower+=20
I remember my symbols like this: the shark (< or >) likes to eat the larger value. :D
In response to Avren
Yes, I know greater and less, I was just confused =P Thanks for helping one more thing though, It still doesn't work like I want it! It still works if you have a weapon equipped or not.
In response to Renparo
I don't quite understand, is it the cast ice on weapon spell you can't cast without a paticular item? Or something else?
In response to Avren
No, Your supposed to have a weapon equipped if you don't have a weapon you can't do it. But mine lets you do it, weapon or no.
In response to Renparo
Ok, so what you mean is that say if you had the ice wand, you could cast the ice spell?
In response to Avren
Nah, I'm saying you have a regular wand or weapon, cast this spell and it turns ice, adding extra damage to attacks with it.
In response to Renparo
Well, erm first off, review the comments; they will display the main points of the problem.
mob
verb
Cast_Ice_On_Weapon()
if(usr.mana <=10)
usr.mana -= 10
else
usr << " You do not have enough mana!"
if(usr.weapon_equipped == 1) //this should be up more to first check if they have a weapon equip.
usr.weaponpower+=20 //why is this here? shouldn't this only happen if the usr has enough mana?
else
usr << " You do not have a weapon equipped!"
if(usr.ecasted == 0) //hold up; think about it. If you switched items, you could never again cast this ice on another weapon!
usr.weaponpower+=20
usr.overlays += 'Ice.dmi'
usr.ecasted = 1
else
usr << " You already have an element casted on your weapon!"
Here is a more effecient example:
mob
var/mana
var/weapon_equipped
verb
Cast_Ice_On_Weapon()
var/obj/weapon/F //This is so we can check if the weapon already has an element cast upon it
if(usr.weapon_equipped&&usr.mana>=10&&!F.ecast)//you don't need to have ==1, doing what I did checks if it's true.the && checks to make sure that if both are true (save yourself some room and less if statements) continue on.
F.ecast=1 //now the weapon has an element casted upon it
F.weaponpower+=10 //add this much power to the weapon.
//add all your else crap here for telling the user what part of the casting spell went wrong. (EX: You didn't have enough mana!)


obj //This is how you will define weapons now, much easier :) i'm not going into deep detail; you can figure out the rest.
weapon
var/ecast //variables for the weapon type
var/weaponpower
sword //this is a sword weapon (NO DUH)
weaponpower=10 //a default weapon power (you may already have your own defaut settings; use them instead however you wish.)
Ok, this is very vague, so you shouldn't copy&paste. Also, in your damage system, calculate the damage by making the var/obj/weapon/F in your damage proc (or verb) and then adding F.weaponpower to it.

Hope this helps.

- Avren :D
In response to Avren
How, precisely, do you get a value for /obj/weapon/F? In your code, it's null. The rest of it is sort of okay, but you've got massive problems fitting it in with the crappy equipment system being used by Renparo.

Basically, instead of storing a boolean variable telling you which weapon you have equipped, you need to store a reference to the object you have equipped.
In response to Jp
Jp wrote:
How, precisely, do you get a value for /obj/weapon/F?

Well, I would assume that makes a var off the weapon. I only used it to check the weapons variables...
In response to Avren
But it has NO VALUE. It's a variable that is supposed to hold a reference to a /obj/weapon. But this line:

var/obj/weapon/F


Simply defines the variable. It doesn't actually initialise it, and nowhere else in the code do you get a value for that variable.
In response to Jp
Like this?
var/obj/weapon/F = /obj/weapon
In response to Avren
No, that sets it to a type path. You want a reference.

As Renparo's code stands, there's no way to find out what weapon you have equipped. This is a problem with his equipment system.
In response to Avren
Avren wrote:
Here is a more effecient example:
mob
> var/mana
> var/weapon_equipped
> verb
> Cast_Ice_On_Weapon()
> var/obj/weapon/F = usr.weapon_equipped
//usr.weapon_equipped should lead
//straight to the obj in question.
//If not then you're funked.
> if(usr.weapon_equipped&&usr.mana>=10&&!F.ecast)
F.ecast=1
F.weaponpower+=10
>
Fixed, I hope? :p