ID:2102700
 
(See the best response by GinjaNinja32.)
Code:
Sell_Eggs()
var/obj/egg/dEgg = input("Which Egg?","Eggs") in eggs
del(dEgg)


Problem description:
I'm trying to let my user select which egg to sell.
eggs is a list that contains instances of obj/egg

Nothing happens when I activate this verb
Are you sure the 'eggs' list is populated correctly? If the list is empty there'll be no prompt. Your first step should be to verify the contents of the eggs list to make sure it actually contains what you think it contains.

Outside of that, the code you posted should function correctly if the list has valid entries.
obj
egg
name = "Testo"
icon = 'Egg.dmi'
icon_state = "1"
New(n)
..()
name = n


client.mob
icon = 'Eggs.dmi'
icon_state = "ground"
var
balance = 11350;
slots = 10;
eggs[0];
verb
Buy_Eggs()
if(balance <= 100)
usr << "Eggs cost 100 gold!"
else if(eggs.len >= slots)
usr << "You don't have room for more eggs!"
else
eggs.Add(new /obj/egg(input("Name Your Egg","Egg Naming")));
balance -= 100
usr << "[usr] bought an egg."
Sell_Eggs()
var egg_choices[eggs.len]
for(var/n in 1 to eggs.len)
var obj/egg/object = eggs[n]
egg_choices["[n]. ([object])"] = object
var dEgg = input("Which Egg?","Eggs") as null|anything in egg_choices
if(dEgg)
var obj/egg/object = egg_choices[dEgg]
src << "You sold [object]!"
del object
for(var/n in 1 to eggs.len-1)
if(eggs[n]==null)
eggs.Swap(n,n+1)
eggs.len-=1

Check_Balance()
usr << "[usr]'s Balance:[balance] "
Stat()
..()
stat("Eggs","[eggs.len]/[slots]")
statpanel("Eggs",eggs)


Yes, There is a statpanel showing the contents of the list it seems to be populating correctly.

The work around I've found now, which seems super sloppy and totally unnecessary is making another list with referenced to the objects. Then based on which of those is chosen the object is deleted and then swap the first null spot in the list to the bottom and copy it to a shorter list, delete the original and copy the short to the original.

THIS IS SO GROSS AND UGLY and I don't understand why my original code wouldn't work as posted in the first post.
Best response
Replacing your verb with the following works as expected:
Sell_Eggs()
var obj/egg/object = input("Which Egg?","Eggs") as null|anything in eggs
if(!object) return
src << "You sold [object]!"
del object
for(var/n in 1 to eggs.len-1)
if(eggs[n]==null)
eggs.Swap(n,n+1)
eggs.len-=1



I'd suggest using `eggs -= object` rather than deleting it then trying to find nulls:
Sell_Eggs()
var obj/egg/E = input("Which Egg?","Eggs") as null|anything in eggs
if(!E) return
src << "You sold [E]!"
eggs -= E
del E
Thanks! I'll take your word it works and try it out later, it seems solid enough to work!

I appreciate this, I don't have a lot of experience with this. Things seem to work a little weird in byond.