ID:169524
 
obj/techs
Teleport
icon='Techs.dmi'
icon_state="IT"
name = "Teleport"
Click()
usr.Teleport()
mob/verb/Teleport(mob/M in world)
set name="Teleport"
set hidden = 1
if(M==usr)return
if(M.block)return //Line 30
usr.loc=locate(M.x,M.y-1,M.z)
usr<<"You Teleport to [M]"


I get the runtime:

runtime error: Cannot read null.block
verb name: Teleport (/mob/verb/Teleport)
source file: Techs.dm,30
usr: Jiskuha (/mob)
src: Jiskuha (/mob)
call stack:
Jiskuha (/mob): Teleport(null)
Teleport (/obj/techs/Teleport): Click("Techniques")


Any help?

~>Jiskuha
M is not being passed to the verb right heres a small rewrite that should fix that issue

obj/techs
Teleport
icon='Techs.dmi'
icon_state="IT"
name = "Teleport"
Click()
usr.Teleport()
mob/verb/Teleport()
set name="Teleport"
set hidden = 1
var/mob/M = input(src,"Teleport to","Teleport") as mob in world
if(M)
if(M==src)
return
if(M.block)
return
src.loc=locate(M.x,M.y-1,M.z)
src<<"You Teleport to [M]"

you might have to sort the tabs out ^_^ (this is untested)
Whenever you get a runtime error that says, "Cannot read null.something", it means that you tried to read, say, x.something, but x was null.

Also, you should be defining M as "mob/M as mob in world". The "as" operator restricts user input -- in this case, it restricts "M" to being a mob (the "mob/M" part makes the compiler think of M as a mob, but doesn't guarantee that M will be a mob).

mob/verb/Teleport(mob/M as mob in world)
set hidden = 1
if(!M || M == src || M.block) return
src.loc = locate(M.x,M.y-1,M.z)
src << "You teleport to [M]."


Now, look in that if() check above. If M.block is evaluated when M is null, then you'll get a runtime error. The reason that the if() check works there is because of short-circuiting.

Short-circuiting means that the first true value found from left to right completes the evaluation. In other words, if !M is true, then DM won't bother to check if M is equal to src or if M.block is true because it already knows that the if() check is true. The && operator, similarly, uses short-circuiting: the first false value found from left to right completes the equation there.

Short-circuiting ensures that if M is null, the compiler won't evaluate M.block, and therefore, won't give you a runtime.
In response to Wizkidd0123
Thanks guys. I've encountered another problem.

obj/techs
KILL
icon='Techs.dmi'
icon_state="KILLER"
name = "Kill Him!"
Click(mob/M in oview(6))
var/obj/KI/O = new /obj/KI(M.loc) // Line 26
walk(O,usr.dir)
obj/KI
icon = 'Techs.dmi'
icon_state = "KILLERBULLET"
density = 1
Bump(mob/M)
if(istype(M,/mob/))
view(6)<<"OUCH!"
del(src)


This is supposed to find a player in the commanders view and shoot them.

Here is the run time:
<font color=red>
runtime error: Cannot read "Techniques".loc
proc name: Click (/obj/techs/KILL/Click)
source file: Techs.dm,26
usr: Jiskuha (/mob)
src: Ki Beam (/obj/techs/KILL)
call stack:
Ki Beam (/obj/techs/KILL): Click("Techniques")
</font>

Any Help guys?

~>Jiskuha
In response to Jiskuha
"Techniques" is a string of text and being such has no variables (being that its not an atom). You want to add 'as mob' to your Click() argument, or populate a list and ask for a choice from the user.
In response to Jiskuha
Click() simply doesn't work like that. Look it up in the DM Ref: its argument is not the object that clicked it. In Click(), usr is equal to mob that Click()ed the atom. If you want to check and make sure that the clicker mob (usr) was within a certain distance of the object being clicked, then you need to do something like this:

if(!(usr in oview(6,src)) return


By the way, in your example, you abused usr: the default argument for view(), oview(), range(), and orange() is equal to usr.
You're going to run into a lot of grief if you keep trying to use block as a var name. DM has this problem with several built-in procs when you try to use them as a var, and block() in particular causes these issues.

Lummox JR
obj/techs
KA
icon='Techs.dmi'
icon_state="KA"
name = "KA"
Click()
view(4)<<"[usr]: KA..."
sleep(10)
view(4)<<"[usr]: KA..."
sleep(20)
view(4)<<"[usr]: KA!!!"
var/obj/Ka/O = new /obj/Ka(usr.loc)
walk(O,usr.dir)


I want this to shoot at the players current dir. HOWEVER, If they click it. It takes that current dir. So what if they move? It shoots towards their original direction. How can I fix/stop this?


~>Jiskuha
In response to Jiskuha
obj/Ka
layer=13
icon='kat.dmi'
Click()
view(4)<<"[src]: KA..."
sleep(10)
view(4)<<"[src]: KA..."
sleep(20)
view(4)<<"[src]: KA!!!"
var/obj/Ka/O = new(usr.loc)
walk(O,usr.dir)

mob
Login()
..()
new/obj/Ka(src)


That works just fine for me. Maybe it's because you're using 3.5, I'm not sure.

Anyhow, also note how new/obj/Ka(usr.loc) is unneccesary. You only need new(usr.loc) since your variable type is the same type of object that needs to be created.

Prodigal Squirrel
In response to Prodigal Squirrel
Jiskuha wrote:

[snip]So what if they move? It shoots towards their original direction. How can I fix/stop this?[/snip]

~>Jiskuha
In response to Jiskuha
I noticed that. What I was saying is that it updates the direction for me. I don't get the same problem you do.

Prodigal Squirrel
In response to Prodigal Squirrel
Than WTF is all I have to say.

~>Jiskuha
In response to Jiskuha
If you're using 3.5, that could be it. I reverted back to the 342 beta version because I was having too many problems wih 3.5.

Prodigal Squirrel