ID:1790946
 
(See the best response by Fushimi.)
Code:
obj
gear
var/quanity
var/equipitem = TRUE
var/canStack=0
weapon
var/gearstats
var/Equip=0
Common
CDagger
icon='Weapons.dmi'
icon_state="D"
desc = "A common Dagger."
CShield
icon='Weapons.dmi'
icon_state="sh"
Rare
RDagger
icon='Weapons.dmi'
icon_state="D"
RShield
icon='Weapons.dmi'
icon_state="sh"
Elite
EDagger
icon='Weapons.dmi'
icon_state="D"
EShield
icon='Weapons.dmi'
icon_state="sh"
verb
Equip()
set src in usr
switch(src.Equip)
if(0)
src.Equip=1
usr.strength += src.gearstats
usr.defense += src.gearstats
_message(usr,"[src.gearstats]","red")
if(1)
src.Equip=0
usr.strength -= src.gearstats
usr.defense -= src.gearstats
_message(usr,"[src.gearstats]","red")

verb
Get()
set src in oview(1)
usr.InfoShow("You pick up [src]")
usr.AddGear(src)
del(src)


Here is the AddGear proc:
mob/proc
DropGear(obj/gear/o)
if(o.canStack && o.contents.len)
var/obj/gear/thegear=pick(o.contents)
thegear.loc=src.loc
if(o.contents.len)
o.quanity="x[o.contents.len+1]"
else
o.quanity="x1"
else
o.loc=src.loc
o.quanity=""

AddGear(obj/gear/o)
var/list/gear=list()

for(var/obj/i in src.contents)
gear+=i.type

if(o.type in gear) //if a similer item is found in the contents
if(o.canStack)
var/obj/gear/thegear
for(var/obj/i in src.contents) if(i.type == o.type) thegear=i
if(thegear)
thegear.contents+=o
thegear.quanity="x[thegear.contents.len+1]"
else
src.contents+=o
o.quanity="x1"
else
src.contents+=o

else
src.contents+=o
o.quanity="[o.canStack ? "x1" : "[o.quanity]"]"


and here is the updateBag() proc:
updateBag()
var/i = 1
spawn(50)
winset(src,"Bag.bag",{"cells="1x[src.contents.len]""})
winset(src,"Bag.gold","text='[src:Gold]'")
for(var/obj/Items/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
for(var/obj/Equips/Equipped/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
for(var/obj/gear/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
src.updateBag()


Problem description:I have random drops in my game with different rarities, now when I try to pick one up with the Get verb it says I get it but it doesn't show up in my inventory.

Best response
From what I have seen and a quick look, you are deleting the 'gear' after calling AddGear(src) on the Get() procedure.

Also, updateBag() seems to be an infinite loop, I would suggest using an actual loop rather than recursion here.

EDIT:
            verb
Get()
set src in oview(1)
usr.InfoShow("You pick up [src]")
usr.AddGear(src)
// del(src)


updateBag()
set background = 1
while(src)
var/i = 1
winset(src,"Bag.bag",{"cells="1x[src.contents.len]""})
winset(src,"Bag.gold","text='[src:Gold]'")
for(var/obj/Items/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
for(var/obj/Equips/Equipped/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
for(var/obj/gear/a in src.contents)
src << output(a,"Bag.bag:1,[i]")
if(a.equipitem == TRUE)
src << output(a.suffix,"Bag.bag:2,[i]")
else
src << output(a.desc,"Bag.bag:2,[i]")
src << output(a.quanity,"Bag.bag:3,[i]")
i++
sleep(50)

Let it be known you should only update the bag while the user is looking at it as well. So, performa check if the user is looking at the bag. If not, then break (or return if you are doing it in the for loop).

Fushimi is right. Don't make infinite loops. You're only crashing your game one line at a time.
Problem solved, thanks Fushimi. And noted, Xirre.
Was reviewing, and just as a side note:

- updateBag() must only run once. (removing the loop)
- In order to keep the player updated, update the bag contents whenever you Get/Drop/Interact with an object that is to be contained in that grid, as I see, the procs involved would be:
- DropGear()
- AddGear()
- Equip()

Just appending:
spawn src.updateBag() // for DropGear() and AddGear()
spawn usr.updateBag() // for Equip()
In response to Fushimi
I just made a proc to check if the player is looking in bag and if so it'd update the bag.