ID:170912
 
One thing I have not learned yet is how to pass a certain var. Jon88 was trying to teach me but i'm still having problems. Could someone really fast just like explain it to me. Also, if I have to vars for a text parser, and the proc i'm calling only expects one var. When the text parser finds that word, it doesn't work because it expects 1 var and gets to or something.
Without seeing what you're trying to do or where you've stumbled here, it'd be difficult to help you. Some code would be good.

Lummox JR
In response to Lummox JR
Yeah I thought that, thats why I was sort of hoping for an explenation. But alright....:

var/list/Attacking = list("Silencio" = "<i>Silencio</i>", "Expelliarmus" = "<i>Expelliarmus</i>")
var/list/Passive = list("Lumos" = "<i>Lumos</i>")
mob
proc
Lumos(mob/Caster)
see_invisible = 2
spawn(50)
see_invisible = 0
Silence(mob/Caster,mob/Defender)
if(Defender)
if(Caster.equiped)//21
if(!Caster.Silenciod)

Defender.Silenciod = 1
sleep(70)
Defender.Silenciod = 0
view(6) << "<I>[Caster] used Silencio on [Defender]</I>"
else
Caster << "You have been Silenced, please wait till spell wears off.!"
else
Caster << "Bug...report to N1ghtW1ng"

Expelliarmus(mob/Caster,mob/Defender)
if(Defender)
if(Caster.equiped)//21
if(!Caster.Silenciod)
Defender.equiped = 0//22
var/obj/wand/W = locate() in Defender
if(W)
W.loc = locate(Defender.x-2,Defender.y-1,Defender.z)
Defender << "Your wand was thrown from your hand by [Caster]!"
else
Caster << "You'r attacking a defenseless Wizard!"
else
Caster << "You have been Silenced, please wait till spell wears off.!"
else
Caster << "Bug...report to N1ghtW1ng"



mob
proc
SpellFinder(mob/Caster,mob/Defender,msg as text)
var/spellname
if(equiped)

if(spellname in Attacking)
if(findtext(msg,spellname) == 1)
call(src, spellname)(mob/Caster,mob/Defender)
return Attacking[spellname]
return msg
if(spellname in Passive)
if(findtext(msg,spellname) == 1)
call(src,spellname)(mob/Caster)
return Passive[spellname]
return msg
return msg
else
return msg
mob
verb

World_Say(msg as text)
world << "[src.name] : [SpellFinder(msg)]"


If you see anything else that looks wrong, can you please tell me, Thanks.
In response to N1ghtW1ng
N1ghtW1ng wrote:
If you see anything else that looks wrong, can you please tell me, Thanks.

Well for starters you never said what you were trying to change in that code and what you were having trouble with.

I do see a couple of minor things in SpellFinder(), just design issues really. First, the "as text" part in the arguments is unnecessary unless you end up using this proc as a verb. Second, that same proc has the line "return msg" several times when it's only needed once; in fact in one place it's preventing a second loop from running. Just put that at the end and anywhere you need to bail out of a loop.

I also suspect the entire if(spellname in Passive) block is indented too far.

Lummox JR
In response to Lummox JR
Alright, what i'm having problems with is, when ever I call any of the Spells it doesn't work. It use to work until I added the whole attacking thing with the mob/Caster and mob/Defender.

Also, yeah I was sorta editing before as I was posting and tabbed it over I forgot why...but yeah. Also, don't I need the other return's incase it doesn't find the Spell in the list?
Ok, well. It's simple, really. You're probably already doing it without knowing what it is. Say all mobs have a var called HP. Most do, so it's a good one to use. Now, let's say when your mob is hit, it checks the damage against it's HP, which most do. For the sake of argument (heh), though, let's say you want the check to happen in a global proc, so you can't just use src.HP in the mob's own proc. To do this, we need to pass the damage and the mob's HP to this global proc, because it has no direct reference to either, unlike the mob.

mob
var
HP = 100


Ok, so there is our variable, HP belonging to the mob. Simple enough. Let's do the damage checking proc now. It's global, remember, so it just starts off the left under the word proc. It doesn't belong to anything, that's why it's global. Anyone can use it.

proc
DamageCheck()


But, we need to pass the HP of the mob and the damage to the DamageCheck() proc, we do that by first telling the proc it should expect 2 arguments. We need to name them as well, so let's do that now.

proc
DamageCheck(var/Damage, var/CurrentHP)


See how that works? DamageCheck() now expects two variable, which it knows by the names Damage and CurrentHP. These variables only work inside the DamageCheck() proc, so you won't be able to use CurrentHP elsewhere without declaring it again. Anyways, now we have the proc just waiting for these values to be passed to it, so how do we do that? Easy, just call the proc and fill the values in the () when you call it.

mob
verb
Attack(var/mob/M as mob in oview(1))
var/attack_power = rand(10, 30)
DamageCheck(attack_power, M.HP)


See how that works? We made a call to DamageCheck() and placed our values in the () after the proc's name. The order has to match the order of our proc definition above, unless you name the arguments. That's just a fancy way of saying:

mob
verb
Attack(var/mob/M as mob in oview(1))
var/attack_power = rand(10, 30)
DamageCheck(CurrentHP = M.HP, Damage = attack_power)


See there? We reversed the position of the values, but it's ok, because we told the proc which is which by applying the name we gave the vars in our original proc defintion to the values we are passing. The proc will be able to look at the variables, see they have names it recognises, and know which is which, even out of order.

Optional arguments is another can of worms, though. If you'd like more information on that topic, I suggest a more experienced programer. I have no real experience with the process myself. I hope this has helped.

~X
In response to Xooxer
Yes, that helped some. I am begining to understand it a little more. My problem though is that my text parser is expecting 2 vars, but my proc that is called by it only is expecting one I think. Well it doesn't work >.>. So yeah...if you wanted to take a look its under Lummox's post.
In response to N1ghtW1ng
Ok, well you don't need all 3 variables to be passed to the SpellFinder() proc. The only one you need is the msg itself. The src of the SpellFinder() proc would be the caster, so there's no need to pass that variable. The only thing you'll have trouble with might be determining who the defender is. As it stands now, there is no way for the code to know who the caster is casting the spell on.

You'll need to have some sort of targeting system, whether it's a simple random pick of someone in a certain range, the caster clicking to select target, or some other means, you have to tell the game who to cast the spell on. Right now, you're not. That's probably the main point of confusion for you. You have the variable, you just don't have a way to fill in it's value.

~X
In response to Xooxer
Alright I think I figured it out now, but i'm still having some problems.

mob
proc
SpellFinder(msg)
var/spellname
if(equiped)

if(spellname in Attacking)
if(findtext(msg,spellname) == 1)
call(src, spellname)(src,target)
return Attacking[spellname]
return msg
return msg
if(spellname in Passive)
if(findtext(msg,spellname) == 1)
call(src,spellname)(src)
return Passive[spellname]

return msg
return msg
else
return msg
mob
verb

World_Say(msg as text)
world << "[src.name] : [SpellFinder(msg)]"

mob
var/target = ""
Clickable

Click()
if(usr.target != "[src.name]")
usr.target = "[src.name]"
while(1)//not sure about this part, if there is a better way can someone tell me
if(!src)
usr.target = ""
break


else
usr.target = ""


I know I made a loop in Click() but I couldn't think of a better way. Also now I can read the message's in worldsay, but the spell does not activate.
In response to N1ghtW1ng
You don't need that while() loop, just asign the player that was clicked as the target. Also, your top if()s in SpellFinder() should be for() loops, so it looks at all the spells of the type. The way you had it the if()s would never be true because spellname was never set to anything. Also, you're returning the msg when you don't need to. Just return if(equiped) is false, and after the two for() loops. Otherwise, it'll return the msg if the spellname isn't the first item in the first list. Try this instead:

mob
proc
SpellFinder(msg)
var/spellname
if(equiped)

for(spellname in Attacking)
if(findtext(msg,spellname) == 1)
call(src, spellname)(src,target)
return Attacking[spellname]

for(spellname in Passive)
if(findtext(msg,spellname) == 1)
call(src,spellname)(src)
return Passive[spellname]

return msg
else
return msg
mob
verb

World_Say(msg as text)
world << "[src.name] : [SpellFinder(msg)]"

mob
var/target = ""
Clickable

Click()
..()
usr.target = "[src.name]"


~X
In response to Xooxer
Thanks! It works great now, just one problem. Not exactly having to do with it but I don't want to make another topic

I get the runtime:
runtime error: Cannot read "\[Master] Night".equiped
proc name: Expelliarmus (/mob/proc/Expelliarmus)
  source file: Spells.dm,40
  usr: the j (/mob)
  src: the j (/mob)
  call stack:
the j (/mob): Expelliarmus(the j (/mob), "\[Master] Night")
the j (/mob): SpellFinder("Expelliarmus")
the j (/mob): World Say("Expelliarmus")



The proc is:

Expelliarmus(mob/Caster,mob/Defender)
if(Defender)
Caster << "1"
if(Caster.equiped)
Caster << "2"
if(!Caster.Silenciod)
Caster << "3"
if(Defender.equiped)//40
Caster << "4"
var/obj/wand/W = locate() in Defender
Caster << "5"
if(W)
Caster << "6"
W.loc = locate(Defender.x-2,Defender.y-1,Defender.z)
Caster << "7"
Defender << "Your wand was thrown from your hand by [Caster]!"
Caster << "8"
else
Caster << "[Defender] does not have his wand equiped!"

else
Caster << "You have been Silenced, please wait till spell wears off.!"
else
Caster << "Bug...report to N1ghtW1ng"
else
Caster << "10"


Yeah..I debugged it and it only goes to #3.

Thanks again, for helping me with the parser, and to anyone who helps with the runtime.
In response to N1ghtW1ng
I was wondering about that myself, actually, but thought you were going to handle locating the target by their text name. The problem is back in your targeting system, the Click() proc for Clickable mobs. You're setting the usr.target to the text name of the target, not to the mob itself. Change those lines from usr.target = "[src.name]" to usr.target = src. Then it will pass the mob to your spells, not the mob's name.

~X
In response to Xooxer
Thanks, that got it working. I understand the Passing arguement's also. So thanks!