I've just started creating my first RPG (and my first game, for that matter), and I've been working on the level up system. However, I cannot quite seem to get it to work. This is my stats, GainEXP and LevelUP procs:
-----------------------------------------------------------
mob
icon = 'player.dmi'
var
HP = 30 //define a new variable called HP, with a value of 30
MaxHP=30
Level = 1
EXP = 0
EXPNeeded = 15
Strength = 2
wealth = 10
proc/GainExp(n) // gain n experience points
EXP+=n
if(EXP>=EXPNeeded) LevelUp()
proc/LevelUp()
++Level
src << "You levelled up! (Level [Level])."
MaxHP=26+4*Level // 26+(4*1) = 30, the original value
HP=MaxHP
Strength = Level*2
EXPNeeded=15*Level
-----------------------------------------------------------
And this is my DeathCheck proc:
---------------------------------------------------------
proc
DeathCheck() //checks to see if an attack is deadly
if (HP <= 0) //if the defender's HP is low enough...
world << "[usr] killed [src]!" //do the death messaging
del(src) //delete whatever just died
----------------------------------------------------------
I believe I am supposed to have a GainEXP line at the end of my DeathCheck, but I'm not sure what the exact code is. Any advice?
1
2
ID:166175
Sep 10 2006, 3:57 pm
|
|
Sep 10 2006, 6:38 pm
|
|
Mainly, the DeathCheck proc doesn't have any way to tell who the killer is. To do that you have to send the attacker as an arg to the DeathCheck proc. Plus that also solves the problem of who to award the XP to.
|
mob From a few things I've looked at this will probably work. |
In response to Abel Night
|
|
Well, I tried editing the code as you've shown me, and the program runs. However, when I attack the enemy, I get the following error:
runtime error: Cannot read null.HP proc name: DeathCheck (/mob/proc/DeathCheck) usr: RoadToDawn (/mob) src: the wolf (/mob/wolf) call stack: the wolf (/mob/wolf): DeathCheck(null, null) RoadToDawn (/mob): attack(the wolf (/mob/wolf)) How do I fix this? The enemy will not die so I don't know if the EXP will work yet either. My entire code: (Except for turf settings) mob |
In response to RoadToDawn
|
|
Your DeathCheck() is screwed.
proc You also need to add arguments to your DeathCheck() call. M.DeathCheck(src) |
In response to Jp
|
|
proc I just changed my DeathCheck proc to look like you've said, and now I'm recieving this error: fantasy.dm:50:error:Attacker.GainEXP:undefined var It looks like this is because the term 'Attacker' hasn't been used anywhere else? About other line you posted, where exactly does that go? I'm totally new to Byond so I'm pretty clueless. |
In response to RoadToDawn
|
|
Not quite, matey. Look closely at what I posted. See how I took out mob/Victim, not mob/Attacker? Change mob/Victim to mob/Attacker.
As for the 'other piece of code', look through your code to see where you call DeathCheck(). Notice that you've got a variable declared for the DeathCheck() proc, but you don't pass one to it in the call? That's what I'm talking about. You need to throw a variable representing the attacker in there. |
In response to Jp
|
|
mob I have updated it like this. However, I get the error: fantasy.dm:51:error:Victim:undefined var I assume this is because Victim is now an undefined term, and as Victim hasn't been used anywhere else I don't think it is the right term. If I replace Victim with src (So del(src)) the program runs fine, I can kill enemies, but I still don't gain any EXP (as far as my stats tell me) Thanks |
In response to RoadToDawn
|
|
It should be del(src). You should also switch 'usr' for 'Attacker' in the DeathCheck() proc - usr is unsafe in procs.
Are you sure you don't get EXP? I can't see why you wouldn't... |
In response to Jp
|
|
Well, I've changed it as you have said. When I kill my second wolf (therefore netting enough EXP to level up) I recieve the following error:
runtime error: Cannot read null.Level proc name: LevelUp (/mob/proc/LevelUp) usr: RoadToDawn (/mob) src: RoadToDawn (/mob) call stack: RoadToDawn (/mob): LevelUp(null) RoadToDawn (/mob): GainEXP(10) the wolf (/mob/wolf): DeathCheck(RoadToDawn (/mob)) RoadToDawn (/mob): attack(the wolf (/mob/wolf)) Can you make any sense of this? |
In response to RoadToDawn
|
|
proc Your GainEXP() proc etc were meant to be mob/proc not just proc/ |
In response to Rickoshay
|
|
I have altered it like you said. My code now looks like this:
mob Now, when I try and Run, I reieve this error: fantasy.dm:50:error:A.GainEXP:undefined proc Do you know why? |
In response to RoadToDawn
|
|
proc |
In response to Rickoshay
|
|
I have removed the 10, and still, the same error-
fantasy.dm:50:error:A.GainEXP:undefined proc If the 10 isn't supposed to be there, how do I define how much EXP is supposed to be recieved when an enemy is defeated? |
In response to RoadToDawn
|
|
proc |
In response to Rickoshay
|
|
fantasy.dm:50:error:M.GainEXP:undefined proc Same error. My entire code once more: mob I think the problem is that the code doesn't know what to do when it gets to GainEXP. What's going on? I don't think the Deathcheck is the problem, I think I am missing code elsewhere... or something. Thanks again |
In response to RoadToDawn
|
|
mob |
In response to Rickoshay
|
|
mob |
In response to Abel Night
|
|
Good gads no. If you don't know what you're doing, please don't offer to help people.
Two major and very very obvious things you did wrong: You added the mob/M argument to the LevelUp() proc which needs no argument at all, thereby massively complicating the proc, and you added two arguments to DeathCheck() which only needs one--the killer. A LevelUp() proc only needs one piece of information: src, the mob leveling up. That's it. A DeathCheck() proc normally needs two pieces of information: src, which must always always always be the vctim, and an argument for the killer. Some very simple death checks don't need to know the killer, so it can be left out of those; some complex ones want to know about the weapon used and other info. Lummox JR |
In response to RoadToDawn
|
|
To an extent you need to trash the code you were given in this thread and go back to what you had before. Only Jp and Top player have steered you right. I'm sad to say Rickoshay has yet to offer good code advice (though one hopes he'll eventually be able to), and Abel Night's advice was horrendously flawed.
Go back to your original LevelUp(), which was correct. Then go back to your original DeathCheck() proc, add a var for the killer, use that to replace usr in the proc, and then call the proc accordingly. Lummox JR |
1
2