ID:1612284
 
(See the best response by Lugia319.)
Code:
obj
proc
Building()
var/O = "/obj/Building_Items/[usr.InHand]"
if(!usr.InHand)
usr.alert("You must have something equipped to build!")
return 0
else
if(src.Amount >= 1)
new src(usr.loc)
src.Amount -= 1
return 1
else
usr.contents -= src


obj
HUD

BuildButton
icon = 'HUD.dmi'
icon_state = "Build"
New()
screen_loc="1,5"
usr.client.screen+=src
Click()
//var/O = usr.InHand
Building()




obj
verb
Equip()
if(!usr.InHand)
usr.InHand = src.name
alert("Equipped [usr.InHand]")

else
alert("You have something equipped already.")



obj
Building_Items
var/Owner
WoodWall

icon= 'Objs.dmi'
icon_state = "WoodWall"
Amount = 1


Problem description:

Ok so pretty much I have a proc in which I am trying to call from clicking a screen object. Only one thing when you click the screen object it builds what you have equipped on in your hand(InHand var). Then it needs to remove 1 off the Amount variable set for objects. The only problem is I can not find any way to !null the variable Amount. Everytime I call it, it cannot be read.
There is no usr for the Building() proc. Pass the mob as an argument and check the mob's inhand variable.

Edit: Also, the thing doing the proc is the building button, which presumably has no amount
I know i'll make it a a usr proc but that's not the problem the problem is how can I access the objects var amount from calling the proc within a screen object?
You need a way to determine which item you want to build, and have that obj call the Building() proc. One of the easiest ways is through a list:

var/list/Crafts = list()
for(var/obj/Building_Obj/B in usr.contents) Crafts += B
var/obj/Building_Obj/O = input("Build which item?") in Crafts
O.Building()


I'd also try to keep the Building() proc under the Building_Obj part of the tree because only Building_Obj are expected to call the Building() proc?
In response to Lugia319
Thank you I have that worked out now
obj/Building_Items
proc
Building()
var/list/Buildables = list()
for(var/obj/Building_Items/B in usr.contents) Buildables += B.type
if(!Buildables)
usr.skalert("You have no buildable items in your inventory!")
return 0
if(!isnull(Buildables))
var/obj/Building_Items/O = input("Build which item?") in Buildables
if(O.Amount > 0)
new O(usr.loc)
return 1
else if(O.Amount < 1)
usr.contents -= O
return

Now the only problem is that it does not subtract the objects variable(Amount) whenever the object is placed. I keep getting the compiler error "O.Amount is not defined."
Best response
Because you changed my code without understanding how it worked. When I added B to the list, I was adding a reference to an OBJECT. Anything that happens to the object in the list will happen to the real object it's referencing. You're adding the TYPE to the list, so O will be a TYPE and not an actual OBJECT. So it doesn't have the variables that an OBJECT would have.

To modify your current code to work, you can either go back to adding objects instead of paths, or you can loop through the player's contents to find an object with that type and make that the object you subtract from amount. Though changing it to objects would require the following change to new()

new O.type (usr.loc)
In response to Lugia319
Ok, I know it's sad to say but I am a little confused. If I take type away and just use the reference of the object like you had it, I cannot get it to create the selected object from the list, I get the error "Cannot create object type."
In response to Lugia319
Thank you so much for all of your help!
obj/Building_Items
proc
Building()
var/list/Buildables = list()
for(var/obj/Building_Items/B in usr.contents) Buildables += B
if(!Buildables)
usr.skalert("You have no buildable items in your inventory!")
return 0
if(!isnull(Buildables))
var/obj/Building_Items/O = input("Build which item?") in Buildables
if(O.Amount > 0)
new O.type(usr.loc)
O.Amount --
return 1
else if(O.Amount < 1)
usr.contents -= O
return


I reread everything about a 1000 times(exaggeration) before I got it working.
I'm gonna take this moment to remind you, again, not to use usr in your procs. usr isn't always defined. Pass the "user" as an argument.
Okay, I'm sorry bad habits are hard to break.