Drop Script Issue

Forgewright
01 May 2020, 08:24I get this error from a new script I added in the drop script of an object named wood_shield. It allows for the dropping of an equipped item.
Error running script: Error evaluating expression 'ListContains(player.equipped, this)': Unable to cast object of type 'TextAdventures.Quest.Element' to type 'System.String'.
This is the drop script.
if (player.shield = this) {
DropEquipped (this)
}
else if (ListContains(player.equipped, this)) { /// A string list but I tried an objectlist too.
MoveObject (this, player.parent.dropdestination)
msg ("You drop your " + this.alias + ".")
}
else {
msg ("You are not carrying " + this.prefix + " " + this.alias + ".")
}
Two days now and can't fix.
I need player.equipped to be a list. My functions work off it.
The function DropEquipped
list remove (object.inventoryverbs, "Unequip")
object.listalias = Replace(object.listalias, " (equipped)", "")
if (HasAttribute (object, "one_handed")) {
player.onehanded = null
}
if (HasAttribute (object, "one_handed")) {
player.onehanded2 = null
}
if (HasAttribute (object, "two_handed")) {
player.twohanded = null
}
if (HasAttribute (object, "shield")) {
player.shield = null
}
object.equipped = False
MoveObject (object, player.parent.dropdestination)
ClearTurn
msg ("You lower your " + object.alias + " and drop it.")
mrangel
01 May 2020, 09:53That's a strange error message; I've only seen that when trying to use ListContains on a dictionary (ooops).
I'll try poking it later, see if I can figure out what's going on.
else if (ListContains(player.equipped, this)) { /// A string list but I tried an objectlist too
A stringlist will generate an error (but I wouldn't expect that error). this
is an object, so it can only go in an objectlist
But beyond that, your logic seems a little confused. player.equipped
is a list of objects which aren't equipped but can be dropped? If an object is in the inventory but not in player.equipped
, it displays the message "You aren't carrying …"? And if an object is both in that list and in the inventory, the player can drop it but it remains in the list?
I hope you know what those variables represent, because it isn't obvious from the names :p

Forgewright
01 May 2020, 10:17player.equipped is a list of objects which aren't equipped but can be dropped?
These are going to be a list of different weapons and or shields that can be equipped and, yes, dropped. I could not see why a player could not drop an equipped weapon so I am trying to do just that.
The other line needs to be changed again. I was messing with the script and left that line from another setup. It should read
else if ( not ListContains(player.equipped, this) and this.parent = player)
(if that is correct code.)
mrangel
01 May 2020, 12:18You don't need to check for this.parent = player
- if it isn't, the drop script won't even be run.
So player.equipped
is a list of items that can be equipped? It seems strange to check that in the drop script; in that case it's only meaningful to know if the item is currently equipped.
Also, looking at the function presented there, it looks like a player can equip two single-handed weapons; but dropping either of them will unequip both but leave the other one with "(equipped)" in its listalias.
This is very confusing code :p

Forgewright
01 May 2020, 13:21I have been making so many changes and in desperation, I posted a script in mid change. I thought the error would be something obvious. I clean it up later. Been up to long trying to fix it. Time to rest and regroup.
The second
if (HasAttribute (object, "one_handed")) {
player.onehanded2 = null
}
should be
if (HasAttribute (object, "one_handed2")) {
player.onehanded2 = null
}
I was thinking of allowing a dual sword thing but needed to fix the issue first. Anyway. lol. I'll get it as close to right as I can the repost.
wait. I grabbed this from an older copy of game.
if (ListContains(player.equipped, this)) {
DropEquipped (this)
}
else {
MoveObject (this, player.parent.dropdestination)
msg ("You drop your " + this.alias + ".")
}
else {
msg ("You are not carrying " + this.prefix + " " + this.alias + ".")
}
Oh yeah, the List player.equipped is not a list of objects that can be equipped but are equipped at the time.
mrangel
01 May 2020, 17:50I also note that you're using player.parent.dropdestination
- that's a bad idea, because the drop script is also run when the player enters "put X in Y".
In a drop script, you should use the provided variable destination
to tell you where the object should go. This will always be the place an object would be sent to if there wasn't a drop script (dropdestination if it exists, game.pov.parent otherwise, and a container if the player's command was "put X in Y")
Hope you don't mind me poking at your code; but thought it might be easier to point out a potential problem that might not be so obvious.
From the code I see so far (kind of guessing what some of your variables are used for), I suspect that I would have it looking more like:
message = "You drop your " + this.alias + "."
foreach (slot, Split("onehanded;onehanded2;twohanded;shield")) {
if (GetAttribute (player, slot) = this) {
message = "You lower your " + this.alias + " and drop " + this.article + "."
set (player, slot, null)
list remove (this.inventoryverbs, "Unequip")
this.listalias = Replace (this.listalias, " (equipped)", "")
}
}
MoveObject (this, destination)
ClearTurn
msg (message)

Forgewright
01 May 2020, 18:42Well, now that I've rested a bit and went over your advice, I didn't realize when making your own script that some of the default Quest functions stayed in effect.
I just need to add this to the object's drop script. (For Equippable objects)
this.equipped = False
player.shield = null
list remove (this.inventoryverbs, "Unequip")
this.listalias = Replace(this.listalias, " (equipped)", "")
MoveObject (this, player.parent.dropdestination)
ClearTurn
msg ("You lower your " + this.alias + " and drop it.")
Sheesh and Thanks 😁

Forgewright
01 May 2020, 18:55Oh, added a line to remove any bonus the item gives.
do (player.onehanded, "no_bonus")
And I should be able to create a type for each kind of equipment item and add this whole drop script to it. Right?
mrangel
01 May 2020, 20:40Presumably with the line player.shield = null
being different for each type :-p
You also still have player.parent.dropdestination
rather than destination
; and you're now not checking if the object is equipped.
Assuming that this.equipped
is set to true when the object is equipped, that would be:
ClearTurn
MoveObject (this, destination)
if (this.equipped) {
this.equipped = False
player.shield = null
list remove (this.inventoryverbs, "Unequip")
this.listalias = Replace(this.listalias, " (equipped)", "")
msg ("You lower your " + this.alias + " and drop it.")
}
else {
msg ("You drop the " + this.alias + ".")
}
(I would also expect "Equip" to be added to its inventoryverbs; but maybe you add that elsewhere)