HELP ME! MODERATE QUEST EXPERIENCE! UNKNOWN ERROR! (PART 2) [Solved]
Sh4dowGaming1234
18 May 2019, 05:08Hi again.
You may have seen my post earlier by the same name.
I am using the combat system recommended by the quest documentation here.
https://docs.textadventures.co.uk/quest/#Rpg
If the player attacks a monster without a weapon equipped, you get this error message:
Error running script: Error compiling expression 'Replace(s, "#Attacker#", CapFirst(GetDisplayAlias(attacker)))': FunctionCallElement: Could find not function 'Replace(Object, String, String)'
Does anyone know how to solve this?
P.S DO NO REFER ME TO THE DOCUMENTATION, I'VE CHECKED IT S MILLION TIMES!!!
P.P.S Whoever helps me solve this will get a special benefit when the game is released sometime next month.
mrangel
18 May 2019, 11:22If the player attacks a monster without a weapon equipped, you get this error message:
Answer at the bottom. But I think it makes more sense for me to explain how I go about finding it. That way, you know how to solve similar problems in future.
OK, the error in this case is that it can't find a function with the signature Replace(Object, String, String)
. If you've read the docs, you know that the signature of the Replace function is Replace(String, String, String)
.
So, the first argument passed to Replace is of the wrong type - it's an object, and it should be a string.
90% of the time, if a variable is an object and it shouldn't be, this is because it's the special object null
.
The first parameter in this case is in the variable s
. So if you search in the library code for that line (it's in the function AttackReport), and scroll up to find where s
is set, you'll find your problem. In this case, s
is the first parameter of that function.
So, somewhere in your code, the function AttackReport
is being called with the first parameter being either null
or another object. So next we search the code for where AttackReport
is being called from.
AttackReport
is called to the function DoAttack
. Its first parameter is either weapon.critdesc
, weapon.attackdesc
, or weapon.missdesc
.
The attributes attackdesc
, critdesc
, and missdesc
should all be strings. It's unlikely that you would have accidentally set one of them to be an object. So the most probably answer is that you have a weapon on which some of the attributes attackdesc
, critdesc
, or missdesc
are missing.
Now, this happens when the player is unarmed. So what is weapon
when the player is unarmed? weapon
is the second parameter to DoAttack
, se we need to look through the code to find out what the second parameter is when the player is unarmed.
In the attack command, you have this code:
if (player.equipped = null) {
DoAttack (player, player, object)
}
else {
DoAttack (player, player.equipped, object)
}
So, when the player is unarmed, the variable weapon
is the player object itself.
Most likely (unless there's some other code interfering with it that I haven't seen), this error means that your player
object doesn't have string attributes named attackdesc
, critdesc
, and missdesc
.
Sh4dowGaming1234
19 May 2019, 01:05Thank you so much mrangel!
I checked the code, added the attackdesc
, misdesc
, and critdesc
to the player and it works fine.
Thanks for the explanation as well.
Most people on the quest forums don't usually go into that much detail.
I have read the docs, and I can't believe I missed that.
As a result, I will stick to my promise of the benefit.
Type this code once to get $2000 worth of in-game currency.
Thanks a lot.
Sh4dowGaming1234