ID:139283
 
Code:
var/list/PhoneNumbers= list()
var/list/NumberOwner= list()
Register()
set background=1
set name="Register for E-Device Contact"
if(usr.HasPhoneNum==1)
usr << "<font color = red>E-Device: You are already registered on E-Device Contact System"
return
else
usr << "<font color = red>E-Device: Generating your code"
var/random=rand(000000,999999)
while(random in PhoneNumbers)
random=rand(000000,999999)
usr.PhoneNumber=random
usr << "<font color = red>E-Device: Your code is [usr.PhoneNumber]"
PhoneNumbers+=usr.PhoneNumber
src.Ownerz=usr
usr.HasPhoneNum=1
NumberOwner+="[usr]"
Call()
var/O=usr.PhoneNumber
if(usr.HasPhoneNum==0)
usr << "<font color = red>E-Device:An Error Occured! Your not registered on the E-Device Contact System!"
return
if(usr.HasPhoneNum==1)
var/N=input("E-Device: Input the code of the person whom your trying to call") as num
for(var/mob/P in world)
if(P.PhoneNumber==N)
var/mob/M=P
if(N in PhoneNumbers)
usr << "<font color = red>E-Device:Calling [N]"
if(M.PhoneNumber==N)
M<<"<font color = red>E-Device: The Number [O] is calling, Answer it?"
switch(input(M,"Will you answer the call?","Call") in list("Yes","No"))
if("No")
usr << "<font color = red>E-Device: The Call was rejected by [N]"
if("Yes")
usr << "<font color = red>E-Device: The Number [N] answered the call. Starting the Calling Mode..."
usr.Calling=1
M.Calling=1
usr.TalkingWith="[M]"
M.TalkingWith="[usr]"
sleep(300)
usr<<"<font color = red>E-Device: The person whom your trying to call may be away or cant answer your call"


Problem description:

I had got all done, cept the calling verb... it wont work, once i call, the person who owns the Number wont get the input o.o so its the usr who choose the Yes or No thing. btw i coded this real quick so i think there are errors but wondered where...

Tell me if you need more explanation

Thanks
~Kip
ArckKip1 wrote:
[...]

I had got all done, cept the calling verb... it wont work, once i call, the person who owns the Number wont get the input o.o so its the usr who choose the Yes or No thing. btw i coded this real quick so i think there are errors but wondered where...

Tell me if you need more explanation

Thanks
~Kip

From just glancing at your code, I don't see anything that really jumps out at me. However, when you're dealing with multiple references it helps to debug your code and see if "P", "M", src, or usr are what you assume they are.

This case sounds like a simple which reference is who. Therefore, I would debug M and P by putting world << M underneath var/mob/M = P. You might not know it but you could be defining a variable as the wrong reference.

Also, I noticed a couple other things that you might want to think about:

- If you're planning on having a lot of mobs and you include NPC as part of the mob tree, and only players are able to call each other then there are two alternatives that will better suit your needs/optimize your code. You should use a for() loop to either search only clients and then access the client.mob variable or only the player mob's type. That will dramatically lower the overhead later on if you're planning on having a large server with a large amount of mobs.

- You probably don't need usr.HasPhoneNum, instead you could just see if usr.PhoneNumber is not 0, null or "" by simply doing if(usr.PhoneNumber).

-By checking if the number is in the phone number list before the for loop, it won't check every single time for every single mob. And on that note, you should break the loop when it finds the correct mob.

- Lastly, here's just an alternative solution: If numbers are static, you could use an associative list with PhoneNumber attached to a player's ckey. So when you're storing a number you can do something like:

var/random = rand(000000,999999)
while(random in PhoneNumbers)
random=rand(000000,999999)
usr.PhoneNumber = random
Phonenumbers += usr.PhoneNumber[usr.ckey] // If my number is 123456, it will add to the list 123456 = kalzar


Then later on when you're calling someone

if(usr.PhoneNumber)
var/N = input(usr, "E-Device: Input the code of the person whom your trying to call") as num|null
if(N && PhoneNumbers && PhoneNumbers[N])
for(var/mob/player/P in world) // Or whatever your player type is
if(PhoneNumbers[N] == P.ckey)
P << "<font color = red>E-Device: The Number [usr.PhoneNumber] is calling, Answer it?"
switch(input(P,"Will you answer the call?","Call") in list("Yes","No"))
if("No")
usr << "<font color = red>E-Device: The Call was rejected by [P.PhoneNumber]"
if("Yes")
...



I didn't run or test any of this so take it with a grain of salt as just a different way of approaching your problem.
Fixed, just misplaced for() proc >:D