ID:149855
 
This code is listed under: mob/npc
Item is sold can create and placed into the usr.contents. All of this works fine. The only problem now is, since I added weight into my game I need to be able to get the item being sold's IW=item weight (obj/item.iw) and pass it to the WCheckA which will find the items iw value and then add it to the player's weight. Right now when you buy a beer it just gives it to you as before but no weight increase. Everything else works fine, -= if you drink it, it -= if you drop it, and it even += if you pick it up, but all those verbs are listed under the obj/s themselves.

LJR

Code:


new/obj/drinks/beer(usr)
var/obj/O = usr.contents
O.WCheckA(O.iw)
Check out the reference entry for the Entered() proc and look at the example. It shows an interesting way to use mob/Entered() for a system like the one you are working on.
In response to Shadowdarke
Shadowdarke wrote:
Check out the reference entry for the Entered() proc and look at the example. It shows an interesting way to use mob/Entered() for a system like the one you are working on.

Nice, but I've already got this much working. I need to be able to get that IW's var passed so its added. I think I read an error in my code where it said iw was null.

LJR
Try this?

var/obj/drinks/beer/B = new(usr)
B.WCheckA(B.iw)
In response to Shadowdarke
I got it!!!
I just made O = new/drinks/beer

:)
LordJR wrote:
new/obj/drinks/beer(usr)
var/obj/O = usr.contents
O.WCheckA(O.iw)

Each of those lines worries me:

  • new/obj/drinks/beer(usr) - Nothing is receiving a reference to this new drink. If you don't intend to use that reference, but just want to create the obj, that's fine; but that doesn't seem to be the case from your code, since you're also interested in its weight. Probably better would be: var/obj/drinks/beer/B = new(usr)
  • var/obj/O = usr.contents - Problem: usr.contents is a list, not an obj. If you're looking to find the beer you just created, the above suggested change should do the trick.
  • O.WCheckA(O.iw) - This seems "off". If the WCheckA() proc belongs to an obj, then O.iw will be accessible within the proc as src.iw. In a sense you're providing redundant information here--yet curiously missing is the info about whose weight total is being checked. In this case usr will work for that, but there will no doubt be situations where that's not desirable. I have a hunch the WCheck() proc should belong to the player, and take the obj as an argument.

    Lummox JR