ID:140751
 
Code:
obj
gettable
guns
var
GUN_SOUND_RANGE
weapon
maxDamage
testgun
icon = 'SpaceGuy.dmi'
GUN_SOUND_RANGE = 5
maxDamage = 50
verb
Shoot()
if(!fired)
world << weapon
fired = 1
target = locate(/mob)in oview(5)
if(!target) return
var/obj/bullet/proj = new(src)
for(var/mob/AI/NPCS/m in oview(GUN_SOUND_RANGE))
for(var/mob/M in oview(5))
if(M.fired)
world << "[M] [L]"
walk_to(m,M)
world << "[src],[M]"
sleep(4)
fired = 0

mob/var/mob/target

obj
bullet
icon = 'bullet.dmi'
density = 1
var/mob/attacker
New(mob/M)
..()
attacker = M //Takes M and set it to attacker
src.dir = attacker.dir
walk_towards(attacker, attacker.target)


Problem description:
Objects.dm:17:error:target:undefined var
Objects.dm:18:error:target:undefined var
Objects.dm:19:proj :warning: variable defined but not used

I've also tried usr.target and it doesn't work as well.
You could try moving "mob/var/mob/target" to the top of the file instead of after the function in which its used.

Although, I would suggest passing the target as an argument instead of as a global variable. Takes up less space that way.
In response to RavynousHunter (#1)
What you mean?
Odd, it compiles fine for me when I use the . operator properly.

if(!usr.fired) // I assume this is a mob variable? So you should make sure it's accessing the mob (which in this case is the usr).


usr.fired = 1 // is also a mob variable?


usr.target = locate(/mob)in oview(5) // again, same as above.


usr.fired = 0 // You guessed it! A mob variable again.


The proj warning is because your setting a variable to the new object and then not using it, which defeats the purpose of declaring a variable. I assume what you want to do is update the bullet's attacker variable to the usr? Which you have already done (not the way I would of though).
Seeing as the first argument of the New proc is normally the location I suggest you make sure for certain that the bullet's loc isn't being set to inside the attacker, perhaps replacing that line with:
new /obj/bullet/proj(loc=usr.loc,M=usr)

Will do what is desired. Also I only just noticed that you were actually setting the attacker as the gun and not the usr (who is firing it). Be more careful next time :D
Gamemakingdude wrote:
Code:
mob/var/mob/target 
obj
gettable
guns
var
GUN_SOUND_RANGE
weapon
maxDamage
testgun
icon = 'SpaceGuy.dmi'
GUN_SOUND_RANGE = 5
maxDamage = 50
verb
Shoot()
if(!fired)
world << weapon
fired = 1
target = locate(/mob)in oview(5)
if(!target) return
var/obj/bullet/proj = new(src)
for(var/mob/AI/NPCS/m in oview(GUN_SOUND_RANGE))
for(var/mob/M in oview(5))
if(M.fired)
world << "[M] [L]"
walk_to(m,M)
world << "[src],[M]"
sleep(4)
fired = 0


obj
bullet
icon = 'bullet.dmi'
density = 1
var/mob/attacker
New(mob/M)
..()
attacker = M //Takes M and set it to attacker
src.dir = attacker.dir
walk_towards(attacker, attacker.target)

This was what I was talking about by placing the /mob/ above the rest of the code, so it gets declared first.


Of course, that's somewhat inefficient, as you're making the target of the shot a global variable (or at least that's what it looks like).

verb
Shoot( mob/target in oview( 5 ) )
//insert the rest of your code here


This way you don't take up needless resources with a global target variable. As a rule of thumb, don't use globals if you can avoid it.
Also want to point out that those nested loops you have there are very poorly made.

                        for(var/mob/AI/NPCS/m in oview(GUN_SOUND_RANGE))
for(var/mob/M in oview(5))
if(M.fired)
walk_to(m,M)
sleep(4)
fired = 0


What this actually does is go through every enemy in range, THEN goes through every mob except for yourself, and if THEY'VE fired recently, blah blah blah. However, for each enemy it loops through, it sleeps for 4 ticks and then sets fired to 0, which will then set up a situation where somebody can rapid-fire if there are multiple enemies nearby, as previous shots are now setting fired to 0 every 4 ticks.

What it really should look like is this:

for(var/mob/AI/NPCS/m in oview(usr,gun_sound_range)) //oh and all-caps should be reserved for constants
walk_to(m, usr)
sleep(4)
usr.fired = 0
In response to Garthor (#5)
One more thing. If i make it usr.target i get more errors.
In response to Gamemakingdude (#6)
It's too bad those error messages are just "ERROR: YOU DONE WRONG, GO WHINE AT GARTHOR". It sure would be nice if they instead said what the problem was.