ID:173221
 
Why doesn't this work:

var/B = "[usr.God]"
var/C = "[B]XP"
src.C+=M.XPGive


If you could tell me how to get this to work, I would be very grateful!

~Ease~
You haven't posted nearly enough information on your problem for anyone to be able to help you.
In response to Jon88
Sorry, I just realised what a lack of information I have given!

Okay, well earlier in the game they choose a God. That God is put into the var/God. Here, I want to add a number (M.XPGive) to the experience var of that God. The experience var of that God will always be "The God's Name""XP". So I want to add "M.XPGive" to "[God]XP". How can I do this? I guess that:

var/B = "[usr.God]"
var/C = "[B]XP"
src.C+=M.XPGive


would work, but it didn't!

~Ease~
In response to Ease
src.God:XP+=M.XPGive


Can't have a var inside a var (B = "[usr.God]; C = "[B]XP").
Ease wrote:
Why doesn't this work:
var/B = "[usr.God]"
var/C = "[B]XP"
src.C+=M.XPGive

Lots of reasons!

First, your B var is entirely extraneous; ditch it and put the same expression in the brackets for C instead.

Second, src.C and the local var/C you just defined are entirely different. src.C belongs to the (I'm guessing) mob; C belongs to the proc where you just declared var/C locally. Normally C and src.C would be the same thing, but because you have a local var with the same name, they're not anymore.

Third, given what you appear to be doing in this code, you're misusing usr. No put usr in proc. Ungh.

Lummox JR
In response to Lummox JR
Okay, if I can't define C locally, where should I define it? I have tried defining it with the rest of the mob var, but the compiler doesn't like that : "Vars.dm:53:error:C:undefined var
Vars.dm:53:error:src.God:undefined var
Vars.dm:53:error:text "[]XP":bad variable definition"

~Ease~
In response to Ease
Ease wrote:
Okay, if I can't define C locally, where should I define it? I have tried defining it with the rest of the mob var, but the compiler doesn't like that : "Vars.dm:53:error:C:undefined var

Odd, since you used src.C without any trouble. If it's not a mob var, what is it? If it's just a temporary var, then just define it locally but don't use src.C to reference it.

Vars.dm:53:error:src.God:undefined var

I kinda figured you meant Gold there.

What is src here? You never showed enough of your verb to be clear on that.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Odd, since you used src.C without any trouble. If it's not a mob var, what is it? If it's just a temporary var, then just define it locally but don't use src.C to reference it.

How should I reference it? What exactly is to reference (in the terms of programming)? I have a vague idea, but not great!

I kinda figured you meant Gold there.

Nope, I meant God!

What is src here? You never showed enough of your verb to be clear on that.

Src is (should be - for that is what I intended it to be) the user. By user, I mean the real life, living person, that is playing it. I would post more of my verb here, but I have no internet access and am having to use a different computer to post this post!

~Ease~

In response to Ease
I finally got internet access on my computer! Here is my verb!

mob
proc
deathcheck(var/mob/M) //check to see if your heart still pumps
if(M.HP<=0) //if it is dead continue doing the stuff in here
sleep(5) //sleep 1.5 seconds
if(istype(M,/mob/Monsters)) //if it is a monster that is being checked
var/C = "[src.God]XP"
src.C+=M.XPGive//add it to your exp
src<<"[M] is defeated!" //let yourself know you killed it
sleep(15) //sleep 1.5 seconds to let it sink in
src<<"You gain [XPGive] experience points!" //let yourself know you got some exp
del M //delete the monster, cause it is dead
src.LevelUp() //check to see if you leveled up
src.loc=locate(src.LastLoc) //move to your old location
else //else, if it is a PC
src<<"You have died." //tell them they died
src.HP=src.MaxHP //restore hp
var/B = "[src.loc.type]"
var/C = copytext(B,1,9)
var/D = "[C]TO"
src.loc = locate(D)


~Ease~
In response to Ease
You're using locate() wrong. When it takes one argument it's to look up something by tag or by type path. If LastLoc is a turf, then just set loc to that directly without using locate().

Lummox JR
In response to Lummox JR
LastLoc is an area, not a turf. This is a Text-game, and I am doing everything by areas.

~Ease~
In response to Ease
Ease wrote:
var/C = "[src.God]XP"
src.C+=M.XPGive//add it to your exp

No confuse src variables with local variables. Ungh. ;-)

In non-caveman-speak, use C instead of src.C there.
In response to Ease
Ease wrote:
LastLoc is an area, not a turf. This is a Text-game, and I am doing everything by areas.

Well then, that makes locate() all the worse. You still shouldn't be using locate() that way.

Lummox JR
In response to Lummox JR
Okay, I've got a new problem. But I don't want to start a new thread because it will take up too much of the forum space.

Here is my problem. When I kill the mob/Monsters, which in this case happens to be a "Weak Bandit", I get the error:

runtime error: type mismatch
proc name: deathcheck (/mob/proc/deathcheck)
usr: Ease (/mob/Player)
src: Ease (/mob/Player)
call stack:
Ease (/mob/Player): deathcheck(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): startcombat(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): startcombat(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): startcombat(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
...
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): startcombat(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): mattack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): startcombat(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): Attack(Weak Bandit (/mob/Monsters/Weak_Bandit))
Ease (/mob/Player): battle(/mob/Monsters/Weak_Bandit (/mob/Monsters/Weak_Bandit))
Craydon Wilds (/area/CrWI): Hunt()

Here is my coding:
mob
proc
deathcheck(var/mob/M) //check to see if your heart still pumps
if(M.HP<=0) //if it is dead continue doing the stuff in here
sleep(5) //sleep 1.5 seconds
if(istype(M,/mob/Monsters)) //if it is a monster that is being checked
var/C = "[src.God]XP"
C+=M.XPGive//add it to your exp
src<<"[M] is defeated!" //let yourself know you killed it
sleep(15) //sleep 1.5 seconds to let it sink in
src<<"You gain [XPGive] experience points!" //let yourself know you got some exp
del M //delete the monster, cause it is dead
src.LevelUp() //check to see if you leveled up
src.loc=src.LastLoc
else //else, if it is a PC
src<<"You have died." //tell them they died
src.HP=src.MaxHP //restore hp
var/B = "[src.loc.type]"
var/C = copytext(B,1,9)
var/D = "[C]TO"
src.loc = locate(D)


Can anyone explain why I am getting this error? I know it is NOT to do with the last line; "src.loc = locate(D)" because that only occurs when the player dies, not the monster. Any help would be greatly appreciated!

~Ease~
In response to Ease
First of all, you're calling all those procs recursively. That means the first call (Hunt()) is waiting for all the future calls to finish, and each of them is waiting for all the future calls to finish, and so on. You've got a long list of procs, each of which is waiting for the battle to finish, so that they may simply return. Each of these procs takes up memory. Obviously, if you get into a long battle, or if too many people are battling for a long time, you'll run out of memory, and that's BAD. Either you get a stack overflow error, or it just SLOWS DOWN. Use spawn() to call the procs, like spawn() Attack() or whatever.

Second, your deathcheck is handled very, very weirdly. Apparently, you call src.deathcheck(M), and if M is a monster, you're checking if M should die, and if it's a play, you're checking if src should die. This is totally, totally messed up. src should ALWAYS be what might be dying, and M should ALWAYS be what's trying to kill src.

Third, the problem you NOTICED you are having, is in these two lines:
var/C = "[src.God]XP"
C+=M.XPGive//add it to your exp

C is a text string. M.XPGive is, I assume, a number. They are not the same type, and thus, you can't add them together. It's like trying to add feet and meters. Sure, you could convert feet to meters, but you can't add them directly. I assume you want to add to src.God instead, in which case, why declare C in the first place?

Additionally, a few lines later, you have the line:
src<<"You gain [XPGive] experience points!"

I assume you want that to be M.XPGive, not XPGive.
In response to Garthor
Okay, to the var/C bit. I am not trying to add anything to "src.God" because that has a different job. I have 12 vars, each a var for a certain God in my game. The name of each var is "[The name of the God][XP]" - for example; one of my Gods is called Inchu, so the var would be "InchuXP". The src.God var, is set to a certain God. So it could be set to "Inchu". I am trying to add "XP" to whatever src.God is. That is the name of the var I want to add the XPGive to.

And about the src<<"You gain [XPGive] experience points!", yes, I did mean M.XPGive.

I have also put in the appropriate "spawn()"'s

~Ease~
In response to Ease
Sorry for bumping, but I really need this! Thank you!

~Ease~
In response to Ease
Ease wrote:
Okay, to the var/C bit. I am not trying to add anything to "src.God" because that has a different job. I have 12 vars, each a var for a certain God in my game. The name of each var is "[The name of the God][XP]" - for example; one of my Gods is called Inchu, so the var would be "InchuXP". The src.God var, is set to a certain God. So it could be set to "Inchu". I am trying to add "XP" to whatever src.God is. That is the name of the var I want to add the XPGive to.

And about the src<<"You gain [XPGive] experience points!", yes, I did mean M.XPGive.

What you've been doing so far has had nothing to do with adding to a mob var. You were just adding a string and a number and expecting everything to work out, then not using them at all. Apparently you thought that creating a string instantly made the var containing it a reference to the var you were trying to alter. How you leapt to that conclusion, I have no idea.

I.e., you thought that var/C="whee" makes all use of C equivalent to src.whee. NO. C is the var containing the string; it is not src.whee.

What you're trying to do is change a variable whose name is determined at runtime. For that, you need the vars[] list.

Lummox JR
In response to Lummox JR
Well I fixed the last problem. Thanks to all that helped, especially Lummox Jr!

Here is my next problem. Every time I (the player) dies, I get a runtime error:

"runtime error: Cannot read null.type
proc name: deathcheck (/mob/proc/deathcheck)
usr: Ease (/mob/Player)
src: Super Dragon (/mob/Monsters/Super_Dragon)
call stack:
Super Dragon (/mob/Monsters/Super_Dragon): deathcheck(Ease (/mob/Player))
Ease (/mob/Player): mattack(Super Dragon (/mob/Monsters/Super_Dragon))
Ease (/mob/Player): Attack(Super Dragon (/mob/Monsters/Super_Dragon))
Ease (/mob/Player): startcombat(Super Dragon (/mob/Monsters/Super_Dragon))"

Here is my code for the "Super_Dragon"'s attack :
mattack(var/mob/Monsters/M) //monsters attack
sleep(7) //sleep for 1.5 seconds
if(M) //if it is still alive (precaution in case it isn't
var/hit1=rand(1,18) //chance to hit the monster
var/hit2=(M.Kaif + M.Taet + rand(1,8)) - (src.Kaif + src.Taet + rand(1,6))
if(hit1==1||hit2<=0) //if it equals 1
usr<<"[M] attacks [src] but miss!"
else
if(hit1==18)
var/damage=round(round(M.Putesh-src.Putesh)/2)+rand(-8,8)
if(damage<=0)
damage=1
damage=damage*2
src<<"[M] attacks [src], Terrible blow! [damage] hit points!"
src.HP-=damage
src.deathcheck(src)
else
var/damage=round(round(M.Putesh-src.Putesh)/2)+rand(-8,8)
if(damage<=0)
damage=1
src<<"[M] attacks [src] for [damage] hit points!"
src.HP-=damage
M.deathcheck(src) //check if you are dead


And here is my "deathcheck" proc:

deathcheck(var/mob/M) //check to see if your heart still pumps
if(M.HP<=0) //if it is dead continue doing the stuff in here
sleep(5) //sleep 1.5 seconds
if(istype(M,/mob/Monsters)) //if it is a monster that is being checked
if(src.God=="Inchu")
src.InchuXP+=M.XPGive
else if(src.God=="Malus")
src.MalusXP+=M.XPGive
else if(src.God=="Nalan")
src.NalanXP+=M.XPGive
else if(src.God=="Taet")
src.TaetXP+=M.XPGive
else if(src.God=="Putesh")
src.PuteshXP+=M.XPGive
else if(src.God=="Kaif")
src.KaifXP+=M.XPGive
else if(src.God=="Xu")
src.XuXP+=M.XPGive
else if(src.God=="Chra")
src.ChraXP+=M.XPGive
else if(src.God=="Raj")
src.RajXP+=M.XPGive
else if(src.God=="Eudia")
src.EudiaXP+=M.XPGive
else if(src.God=="Gebor")
src.GeborXP+=M.XPGive
else if(src.God=="Nauti")
src.NautiXP+=M.XPGive
else if(src.God=="Turas")
src.TurasXP+=M.XPGive
else if(src.God=="Alz")
src.AlzXP+=M.XPGive
else if(src.God=="Aul")
src.AulXP+=M.XPGive
else if(src.God=="Uulong")
src.UulongXP+=M.XPGive
//var/C = "[src.God]XP"
//C+=M.XPGive//add it to your exp
src<<"[M] is defeated!" //let yourself know you killed it
sleep(7) //sleep 1.5 seconds to let it sink in
src<<"M = [M]"
src<<"src = [src]"
src<<"You gain [M.XPGive] experience points!" //let yourself know you got some exp
del M //delete the monster, cause it is dead
src.LevelUp() //check to see if you leveled up
else //else, if it is a PC
src<<"You have died." //tell them they died
src.HP=src.MaxHP //restore hp
var/B = "[src.loc.type]"
var/C = copytext(B,1,9)
var/D = "[C]TO"
src.loc = locate(D)
src<<"M = [M]"
src<<"src = [src]"


Thank you for your time!

~Ease~
In response to Ease
Ease wrote:
Here is my next problem. Every time I (the player) dies, I get a runtime error:

"runtime error: Cannot read null.type

This is really easy to find and fix; just search for "type". In this case it's src.loc.type, so obviously src.loc is null. You're not checking properly for that.

mattack(var/mob/Monsters/M) //monsters attack
sleep(7) //sleep for 1.5 seconds
if(M) //if it is still alive (precaution in case it isn't
var/hit1=rand(1,18) //chance to hit the monster
var/hit2=(M.Kaif + M.Taet + rand(1,8)) - (src.Kaif + src.Taet + rand(1,6))
if(hit1==1||hit2<=0) //if it equals 1
usr<<"[M] attacks [src] but miss!"

No put usr in proc. Ungh.

if(istype(M,/mob/Monsters)) //if it is a monster that is being checked
if(src.God=="Inchu")
src.InchuXP+=M.XPGive
else if(src.God=="Malus")
src.MalusXP+=M.XPGive

So you opted not to look up the vars[] list in the reference, I see. If you had, you'd have found a much better way to do this than a zillion if/else blocks.

Lummox JR
Page: 1 2