ID:155616
 
Hey, I've just started learning. I'm practicing by programing random things that come to my head. I have a few questions. The goal here was to make you teleport under a player of your choosing. I got it working but was stumped on a few things.

My initial attempt was this.

            Tele_Plyr()
for(var/client/P)
alert("Are you sure you wanna tel to him?","Tele?","Yes","No")
if("Yes")
usr.x = P.x; usr.y = P.y-1; usr.z = P.z
else
usr << "ok nevermind then"


it told me that P.x was undefined. I know P is defined and i know x, y, & z are defined by default, so how come when i put them together it gives me an error? I came up with the solution you see below but it didnt work.

Then I changed "if(P == client)" to if(P.client) and it worked. Im still a little muddy on how == works so i tried something else. Im a little confused though, isnt "==" checking if the two are equal? Why wouldnt it work?

Edit for random thought: is it because client is a 0 or 1 sum to just check if you are one or not? So == then wouldnt actually be checking anything?

And i just realized i was using for() wrong too in my first attempt.

            Tele_Plyr()
var/list/clientlist
for(var/mob/P)
if(P == client)
clientlist += P
var/mob/chosen = input("Tele to who", "Who") in clientlist
alert("Are you sure you wanna tel to him?","Tele?","Yes","No")
if("Yes")
usr.x = chosen.x; usr.y = chosen.y-1; usr.z = chosen.z
else
usr << "ok nevermind then"
else
return
You defined P as a /client.
/client 's don't have locations. /mob 's, controlled by /client 's, however can have a location such as x, y, and z.
== does check if something is equal as it suggests.

if you use (p.client) its checking to ensure its not null or is a client.

As for your problem you cant grab x,y,z from a client as its a mob variable.

mob/verb/Teleport()
var/list/players = new //this is going to be your selection to choose your teleport player.
for(var/client/clientele) //search the global client list.
if(clientele.mob) players += clientele.mob //add the clients MOB to the player list aswell as ensure the client actually has a mob.
var/mob/teleto = input("choose your player to tele to","cause teleport is win") as null|anything in players // the null anything ensures that something is always returned. a selection or nothing.
if(!teleto) return //this is just so incase they hit cancel it sends em back and doesn't screw with stuff.
if(alert(src, "Teleport to [teleto.name]?","Admin Controls","No","Yes") == "Yes")//i like to stick no as the default. and this also kills the switch statement. as it will only continue with yes.
src.x = teleto.x;src.y = teleto.y;syc.z = teleto.z


The important thing to keep in mind when using client/whatever is if your making a list you always want to either add the mob to the list instead of the client.. or ensure you pull the mob from the client when you add the clients to a list.

~Midget
In response to Midgetbuster
Thanks alot Midgetbuster and Mr.Robert. I didnt realize that clients and mobs were separate, i guess in my mind i thought client belonged under mob as just a type of mob or something. Just to clarify, the last part of your post you're saying that since clients and mobs are separate, i need to make sure that if im intending to do something to the mob, i specify that instead of doing it to the client only. Right?

Also in this line - "var/list/players = new" What is the significance of new here. Is it just incase you already had "players" defined so its specifying that its a new var made only for this situation?

I realized after reading your code and comments that mine didnt work when i chose "No". I added the switch statement and it did work. So i learned another lesson that i cant use more then one if without a switch statement. For some reason i thought i read switch was only for multiple ifs and else. Anyway thanks, learned alot.

In response to Turles
new is used to initialize a list. If it was just list/players it would give you a runtime error. the list must ALWAYS be initialized by using new or making the list already active by having some form of data in it like.. list/players = list(frogger, blogger)

Client is the handler of all actions from interface to mob movement.
Mob is the player itself.

If you want to use clients and mobs in relation use client.mob.(whatever variable you want to access) or mob.client.(whatever client var you want to access)
In response to Midgetbuster
Riight. So that makes sense why when i take out "= list()" from "var/list/clientlist = list()" the verb stops working. I thought it was arbitrary.

Thanks.
In response to Turles
Haha yea i use to think that because my lists use to be like that awhile back and i use to have them set up as list[0] which is an activated list but i decided i didn't want them showing up in my save files until it was populated so i removed the [0] and it didnt work. then i remembered i had to re-initialize the list.

All good fun. Always good to ask if you don't understand something i guess ;p