ID:266513
 
obj
Machine_Gun_Clip
icon = 'obj.dmi'
icon_state = "clip"
verb
Pick_Up()
set category = "Commands"
set src in oview(1)
usr.Clip += 1
Move(usr)

Use(O in usr.contents)
set category = "Commands"
if(O == /obj/Machine_Gun)
O.bullet += 25
del(src)
else
usr << "That doesnt work with that"

Drop()
set category = "Commands"
usr.Clip -= 1
src.loc = locate(usr.x,usr.y,usr.z)

it says O.bullet undefined var how van i fix that
You need to let the proc know what specific type of object var/O is, whatever type actually uses the "bullet" variable.

for example...

You have:
Use(O in usr.contents)

You want:
Use(obj/gun/O in usr.contents)

obj
Machine_Gun_Clip
icon = 'obj.dmi'
icon_state = "clip"
verb
Pick_Up()
set category = "Commands"
set src in oview(1)
usr.Clip += 1
Move(usr)

Use(O in usr.contents)
set category = "Commands"
var/obj/Machine_Gun/O
if(O == /obj/Machine_Gun)
O.bullet += 25
del(src)
else
usr << "That doesnt work with that"

Drop()
set category = "Commands"
usr.Clip -= 1
src.loc = locate(usr.x,usr.y,usr.z)


or somthing, anyways im tired i can barely read straight nitey nite!
O is a variable of unknown type. There is no way to know if O has a var named bullet. However, I am guessing your obj/Machine_Gun does have a bullet var.

You need to cast O as an obj/Machine_Gun. In other words, make a var of type obj/Machine_Gun, set it equal to O, and then perform whatever actions on the obj/Machine_Gun var. I have done this in the code below.

            Use(O in usr.contents)
set category = "Commands"
if(O == /obj/Machine_Gun)
var/obj/Machine_Gun/mg = O
mg.bullet += 25
del(src)
else
usr << "That doesnt work with that"


PS: This is rather like [link].
In response to ACWraith
ACWraith wrote:

Use(O in usr.contents)
set category = "Commands"
if(O == /obj/Machine_Gun)
var/obj/Machine_Gun/mg = O
mg.bullet += 25
del(src)
else
usr << "That doesnt work with that"


Unnessesary. Also, the if statement will always evaluate to false, since types are not in usr. contents.

Use(obj/Machine_Gun/MG in usr.contents)
set category = "Commands"
if(MG)
MG.bullet += 25
del(src)
else
usr << "That doesnt work with that"
In response to Skysaw
Yeh, I should not of cut and pasted so much of the prior proc. I still don't like the "don't use that var - use this one" lesson. A cast tells how to deal with objects of different types.

[edit]
I think you also changed the logic a bit though. The original proc dealt with other types of objs and gave a message. Your code gives a message about an obj that doesn't exist.
In response to Skysaw
> Use(obj/Machine_Gun/MG in usr.contents)
> set category = "Commands"
> if(MG)
> MG.bullet += 25
> del(src)
> else
> usr << "That doesnt work with that"


Just pointing out that you probably intended to use "if(istype(MG))" -- if(MG) would return true for any object.
In response to Spuzzum
Spuzzum wrote:
> > Use(obj/Machine_Gun/MG in usr.contents)
> > set category = "Commands"
> > if(MG)
> > MG.bullet += 25
> > del(src)
> > else
> > usr << "That doesnt work with that"
>

Just pointing out that you probably intended to use "if(istype(MG))" -- if(MG) would return true for any object.

No, I meant if(MG). if(MG) returns true if it exists. We already know what the type is.
In response to ACWraith
ACWraith wrote:
Yeh, I should not of cut and pasted so much of the prior proc. I still don't like the "don't use that var - use this one" lesson. A cast tells how to deal with objects of different types.

[edit]
I think you also changed the logic a bit though. The original proc dealt with other types of objs and gave a message. Your code gives a message about an obj that doesn't exist.

Mine was not a complete code, just a snippet that should replace the similar section in the original code. It doesn't make sense out of context.
In response to Skysaw
No, I meant if(MG). if(MG) returns true if it exists. We already know what the type is.

But you should know that simply saying "obj/Machine_Gun/MG" doesn't guarantee that it will be of that type. We can't tell DS what objects to accept -- it'll give the Use() verb to everything in the user's contents. Unless, of course, I've been under a rock for a little while and missed the new feature in the release notes. =)
In response to Skysaw
Use(obj/Machine_Gun/MG in usr.contents)
set category = "Commands"
if(MG)
MG.bullet += 25
del(src)
else
usr << "That doesnt work"

In response to Justin Sun
Uh, why'd you just repost Sky's code?