ID:169669
 
i wanna make a turf so when you enter it, it switches your spot but... just the z layer, how do i do this?
usr.loc=locate(usr.x,usr.y,z)
Next time use it in DM
Change it if you want. It has to be valid.
turf/zchange
Enter()
usr.loc=locate(x,y,1)
In response to Jay1
Jay1 wrote:
> turf/zchange
> Enter()
> usr.loc=locate(x,y,1)
>


No. I have said it quite a few times now, and I think at least one of them was to you.

What you have there might seem alright to you, as it appears to work at first when you are doing simple and straightforward things; but it doesn't take much to have that code snippet you gave turn buggy as heck.

You need to use Entered when something is happening as a result of entering an object, and you need to make use of the argument the function has instead of using usr.

Your code snippet should be altered to look like this.
turf/zchange
Entered(atom/movable/M)
M.loc=locate(x,y,1)

To show you how easy it is to have your version bug out on you, I will give a simple example.
obj/spawner
var/mob/spawnling
New()
spawn()spawner()
proc/spawner()
while(1)
if(!spawnling)
spawnling=new(loc)
walk_rand(spawnling, 4)
sleep(600)

With a great many things you could add to your code, including the above example, your code snippet would crash and generate runtime errors as the new creature walks around. That is why it is always best to make the code robust so that you won't get errors, or at least will be much less likely to get them.
In response to Loduwijk
No, you've never said anything to me about anything or everything. And my code works fine, I just tried it, and it works like a charm. Why do you have to make everything so complicated? Mine works perfectly, try it.
In response to Jay1
It works for one given situation.
In response to Jay1
Jay1 wrote:
No, you've never said anything to me about anything or everything. And my code works fine, I just tried it, and it works like a charm. Why do you have to make everything so complicated? Mine works perfectly, try it.

Your code, well, sucks. It uses usr abuse, and, guess what? It may warp the wrong person sometimes, and stuff like that. Your code is not robust, nor anything of the sort.
In response to InuTracy
u guys are makin a little to much trouble...
turf
floor
Enter()
usr.z +=1 // change this to hwo many Z u want to change


this is much easier
In response to O-matic
O-matic wrote:
u guys are makin a little to much trouble...
> turf
> floor
> Enter()
> usr.z +=1 // change this to hwo many Z u want to change
>

this is much easier

Wow, just, wow.
1) That won't work, if anything, it will give you a runtime error.
2) Usr abuse
3) Use Entered()
4) I don't think usr.z++ will do anything.
In response to Hell Ramen
4) I don't think usr.z++ will do anything.

I don't think so either.

turf/blah
Entered(O)
if(ismob(O))
O.loc = locate(O.x,O.y,O.z+1)


That might work though. I didn't really read all of the posts, so I don't know if that was even what he was asking for.
In response to Jay1
Jay1 wrote:
No, you've never said anything to me about anything or everything.

[link]

And my code works fine, I just tried it, and it works like a charm. Why do you have to make everything so complicated? Mine works perfectly, try it.

As I said before, yours works in only a very limited environment. It is very prone to bugs, which means it is not perfect. It is easy to break, which I did in my example.

I am only trying to help. I could give you numerous more examples in which that would break down as well, and not only the usr abuse that my previous example showed, but the use of Enter instead of Entered as well.

If you do not believe me, I will write up several test worlds which will demonstrate it in various ways. I would be glad to write them up for people to simply copy/paste into a new environment and put to rest any misguided notions they may have.
turf/warp
var/new_z=2 //Change this for each turf
Entered()
usr.loc=locate(x,y,new_z)


Absolute Zer0
In response to Absolute Zer0
It's good you are trying to help, but usr is a no in most procs. It would help to read other solutions and see why some of them were wrong [link]
In response to N1ghtW1ng
N1ghtW1ng wrote:
It's good you are trying to help, but usr is a no in most procs.

Yes, and to learn more about usr, read the usr lecture!
In response to N1ghtW1ng
If you want something more politically correct, here:

turf/warp
var/new_z=2 //Change this for each turf
Entered(mob/M)
M.loc=locate(x,y,new_z)

I just figured that the use of args might be a little hard for beginners to grasp, you know.

Absolute Zer0
In response to Absolute Zer0
Absolute Zer0 wrote:
> turf/warp
> var/new_z=2 //Change this for each turf
> Entered(mob/M)
> M.loc=locate(x,y,new_z)


You would probably want an if(ismob(M)) check in there as well, unless you don't mind objects of type /obj being affected as well. In such a case, however, you would usually use atom/movable/M.

I just figured that the use of args might be a little hard for beginners to grasp, you know.

Yes, we understand; and that is good to be thinking of them like that. However, getting them in the habit of using usr too much will give them headaches later on when they rely on it in many cases where they should not. Easier now, harder down the road.

On another note, I do like your use of a new_z variable. That is how I do it, and I feel bad for the folks who get themselves into a mess by redoing Entered for every teleporting object. In case you, or anyone, cares, this is how I often set up turf and area to make things extremely simple.
turf
var
new_x=0;new_y=0;new_z=0
Entered(atom/movable/A)
var
X=new_x;Y=new_y;Z=new_z
turf/T
if(X||Y||Z)
if(ismob(A)) //don't bother if you want to let all objects teleport
var/mob/M=A
if(M.client) //again, ignore if you want all mobs to be affected
if(!new_x)X=x
if(!new_y)Y=y
if(!new_z)Z=z
T=locate(X,Y,Z)
if(T)M.Move(T)
//leave out the above if and just move it regardless if you don't mind null loc

And repeat for area.

If I think I may want to have teleporter objects of type obj or mob then I would just do it once for atom.

If I want to allow means of teleportation besides entering, such as using a "Press Big Red Button" verb on handheld teleporter obj then I would make a teleport function instead which does all the work and just call that as needed.

Anywho, just thought I'd toss that out there since it came up. Hope it is helpful to someone.
In response to Absolute Zer0
Absolute Zer0 wrote:
I just figured that the use of args might be a little hard for beginners to grasp, you know.

This argument always annoys me. When we teach science, we don't teach children that the sun revolves around the earth. When we teach history, we don't teach children that President Bush discovered America. Why should programming be any different? Using usr in Entered() is, and will always be, completely wrong. You aren't helping anybody by trying to dumb things down to the point where they don't work. As Einstein said, "Things should be made as simple as possible, but no simpler".

By the way, your Entered() is still wrong, even though you took the usr abuse out: you didn't check to see if M was really a mob. You need the following line, or something similar, under Entered():

if(!istype(M)) return
In response to Wizkidd0123
Wizkidd0123 wrote:
we don't teach children that President Bush discovered America.

Woah, woah, Bush didn't discover America? Where have I been?
In response to Wizkidd0123
Wizkidd0123 wrote:
if(!istype(M)) return


Shouldn't you atleast finish the istype proc? I'd think that
if(!ismob(M)) return

would be more appropriate
In response to Absolute Zer0
Absolute Zer0 wrote:
If you want something more politically correct, here:
turf/warp
var/new_z=2 //Change this for each turf
Entered(mob/M)
M.loc=locate(x,y,new_z)

I just figured that the use of args might be a little hard for beginners to grasp, you know.

Politics don't enter into it. Using arguments is easy, and a newbie should learn how to use Entered() properly, since it comes up in many games. As an absolute first priority they should also learn not to abuse usr. Advising them to do something wrong, not so much a good idea.

Likewise it's important, as others have pointed out, to be sure M really is a mob. Of course in this case the code is probably safe anyway since an obj will just teleport as well.

Lummox JR
Page: 1 2