You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (c *Creature) PickUp(o Objects) bool {
turnSpent := false
for i, v := range o {
if v.X == c.X && v.Y == c.Y && v.Pickable == true {
item := o[i]
c.Inventory = append(c.Inventory, item)
fmt.Println(len(o))
o[i] = o[len(o)-1] // Doesn't it leaks a memory? \/
o = o[:len(o)-1] // It's slice of pointers to struct.
fmt.Println(len(o))
turnSpent = true
break
}
}
return turnSpent
}
After picking item up, len(o) becomes smaller. But item remains on the ground. After another picking up, len(o) is the same as at start of previous call.
It's about pointers?
The text was updated successfully, but these errors were encountered:
After picking item up, len(o) becomes smaller. But item remains on the ground. After another picking up, len(o) is the same as at start of previous call.
It's about pointers?
The text was updated successfully, but these errors were encountered: