ID:155195
 
Basically what I want to happen

User picks up item
Item count goes up 1
If item count is 3 or more
Tell user they are heavy

I don't understand why this won't work. It makes sense to me!

pick_up()
set src in oview(1)
set category = "Object"
loc = usr.contents
item_count ++
if(item_count >= 3)
usr << "Heavy"


The var for item_count is already declared as obj/var/item_count = 0

What exactly am I doing wrong here? I've tried item_count +=1, item_count = item_count + 1 and now I'm trying item_count ++
Penguinsandwich wrote:
item_count +=1, item_count = item_count + 1 and now I'm trying item_count ++

All these are equivalent. They're all right too.

Your problem is, each object has individual item_count. You pickup Object1, and it changes Object1.item_count to 1. Then you take Object2 and it Object2.item_count to 1. Now you have two objects with item_count == 1.
You need to change players variable, if you want to limit his inventory (usr.item_count in this case).
In response to Zaoshi
I figured it out thanks to you! I think this is the correct way to do it:

var/mob/item_count = 0


obj/items
verb

// *****Get and Drop*****

pick_up()
set src in oview(1)
set category = "Object"
if(item_count >= 2)
usr << "You are holding to many things!"
else
loc = usr
item_count ++

drop()
set src in usr
set category = "Object"
loc = usr.loc
item_count --
In response to Penguinsandwich
Penguinsandwich wrote:
I figured it out thanks to you! I think this is the correct way to do it:
>       pick_up()
> set src in oview(1)
> set category = "Object"
> if(item_count >= 2) // has to be usr.item_count otherwise you use object's variable, not player's
> usr << "You are holding to many things!"
> else
> loc = usr
> item_count ++ // same as before
>
> drop()
> set src in usr
> set category = "Object"
> loc = usr.loc
> item_count -- // same as before
In response to Penguinsandwich
var/mob/item_count = 0


This isn't doing what I think you want it to do. This is creating a global variable that of type /mob. I'm pretty sure you want:

mob/var/item_count = 0
In response to Zaoshi
I am trying to make a variable for usr but it can't be accessed within that structure since the structure is under another type. At least I don't know how to do something like that. What I tried instead was creating a global var and doing it that way and it does work.

I tried something like

var/usr/item_count = 0

and

usr
var/item_count = 0

But when I use something like that, it tells me the item_count is undefined, and that's because the variable isn't global, or declared within the obj type parent/subparent path.

Is there a way to reference variables from other types?
In response to Penguinsandwich
...have you ever looked at the guide? It explains the basics of syntax. o_O
In response to LordAndrew
It doesn't explain to me how to reference variables inside of a different obj type.
In response to Penguinsandwich
this works exactly how I want it to work

var/item_count = 0 // Global Var

obj/items
verb

// *****Get and Drop*****

pick_up()
set src in oview(1)
set category = "Object"
if(item_count >= 2)
usr << "You are holding to many things!"
else
loc = usr
item_count ++

drop()
set src in usr
set category = "Object"
loc = usr.loc
item_count --


Unless you know of a way to create something like

usr
var/item_count = 0

and then call that within the obj type path, that is all I know how to do.
In response to Penguinsandwich
You're setting item_count to a global variable (see: [link]). usr points to a /mob, therefore item_count needs to be a /mob variable.
In response to Penguinsandwich
Penguinsandwich wrote:
> usr
> var/item_count = 0


That'd be
mob
var/item_count = 0
In response to Zaoshi
Okay so I declare the mob/var/item_count = 0 but when I try to call it within the obj type, it says undefined. From reading the guide, we can reference variables inside a type using .
like mob.item_count

so I did it like this:

mob/var/item_count = 0
obj/items
verb

// *****Get and Drop*****

pick_up()
set src in oview(1)
set category = "Object"
if(mob.item_count >= 2)
usr << "You are holding to many things!"
else
loc = usr
mob.item_count ++

drop()
set src in usr
set category = "Object"
loc = usr.loc
mob.item_count --



All it tells me is the mob.item_count is undefined within the obj type.
In response to Penguinsandwich
As I said before you need to use usr not mob.

LordAndrew even explained ([link])
In response to Zaoshi
I guess I didn't understand what you had meant. I didn't realize that declaring any variables under /mob appointed all the variables to usr. Thanks for all the help. I think this is what you were all trying to explain to me.

mob/var/item_count = 0
obj
verb

// *****Get and Drop*****

pick_up()
set src in oview(1)
set category = "Object"
if(usr.item_count >= 2)
usr << "You are holding to many things!"
else
loc = usr
usr.item_count ++

drop()
set src in usr
set category = "Object"
loc = usr.loc
usr.item_count --
In response to Penguinsandwich
Penguinsandwich wrote:
I didn't realize that declaring any variables under /mob appointed all the variables to usr.

This is because usr is defined as the type /mob.
The reference even says this.