ID:139474
 
Code:
The verbs:
mob/Trainer/verb
New_Send_Out()
set category = "PokeCommands"
var/mob/Pokemon/P=input(usr,"Select a Pokemon to send out","Select") in usr.pokemonlist
if(P.returned==1&&!usr.client.cont)
P.loc=locate(usr.x,usr.y,usr.z)
usr.PkmInInven-=1
P.returned=0
client.cont=P
client.eye=P
client.perspective=EYE_PERSPECTIVE
P.client.contd=0//if you still want the controled mob to have control get rid of this
else
usr << "[P] isnt in its pokeball!"
return

Return()
set category = "PokeCommands"
var/mob/Pokemon/P=input(usr,"Select a Pokemon to return","Select") in usr.pokemonlist
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
client.cont.client.contd=1
usr.client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[P] Return!"
usr.PkmInInven+=1
return

The vars:
client
var/mob/cont
var/tmp/contd=1


Problem description:
Well, I got those two runtime errors here:

runtime error: Cannot modify null.contd.
proc name: New Send Out (/mob/Trainer/verb/New_Send_Out)
source file: pokemon tab.dm,37
usr: SilverShine (/mob/male1)
src: SilverShine (/mob/male1)
call stack:
SilverShine (/mob/male1): New Send Out()
runtime error: Cannot modify null.contd.
proc name: Return (/mob/Trainer/verb/Return)
source file: pokemon tab.dm,58
usr: SilverShine (/mob/male1)
src: SilverShine (/mob/male1)
call stack:
SilverShine (/mob/male1): Return()

I can't seem to fix them myself. Anyone who is helping me out, thanks in advance.
In your New_Send_out() verb, add "if(P.client)" before "P.client.contd=0"

Your error is caused by the game looking for a client in a mob that doesn't have a client.
In response to Nielz (#1)
But the P isn't a client, it's a pokemon.
In response to Raimo (#2)
Raimo wrote:
But the P isn't a client, it's a pokemon.
Then you can't have P.client as a var.. Client is a built in var with the result 1 or 0. You can't make it check for the owner or whatever you are trying to do, you'd have to make a separate var altogether.
In response to Xyphon101 (#3)
So you're saying that only this line needs changing:
P.client.contd=0
In response to Raimo (#4)
Raimo wrote:
So you're saying that only this line needs changing:
P.client.contd=0

Not that it needs to be changes, you need to think it over for a second.

P.client.contd is saying you want to access the client.contd value for P. Since P doesn't have a client P.client is null therefore you get the runtime null.contd.

If you're trying to have each Pokemon associated with a certain client, you'll have to define a var such as ../pokemon/var/client/c then set c to be an actual client. Then you can call the client's variable as P.c.cont....

Also, client.cont.client.contd=1 needs to be fixed too. If you break this one down too you'll see its wrong. Although cont is a mob, you set it to P which doesn't have a client so you're getting null.contd here too.
In response to Kalzar (#5)
What I have now is this and getting no runtime errors:
    New_Send_Out()
set category = "PokeCommands"
if(usr.client.cont)
usr << "You have already got a pokemon send out!"
return
else
var/mob/Pokemon/P=input(usr,"Select a Pokemon to send out","Select") in usr.pokemonlist
if(P.returned==0)
usr << "[P] isn't in its pokeball!"
return
else
P.loc=locate(usr.x,usr.y,usr.z)
usr.PkmInInven-=1
P.returned=0
client.cont=P
client.eye=P
client.perspective=EYE_PERSPECTIVE
P.contd2=0//if you still want the controled mob to have control get rid of this
usr << "Go [P]!"

Return()
set category = "PokeCommands"
var/mob/Pokemon/P=input(usr,"Select a Pokemon to return","Select") in usr.pokemonlist
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[P] Return!"
usr.PkmInInven+=1
return

And the vars:
client
var/mob/cont
var/tmp/contd=1
mob
var
contd2=1


Also, I can't figure out how to do it for this line:
var/mob/Pokemon/P=input(usr,"Select a Pokemon to return","Select") in usr.pokemonlist

at the return verb. I want to make it only if the P is in view and if P is part of the usr's pokemonlist. So clearly, P should be in usr's view and should be part of the list.
I've tried:
for(var/mon/Pokemon/P in usr.pokemonlist&&view())

But that doesn't seem to work.

Thanks for all the help untill now.
In response to Raimo (#6)
Do a for loop through the pokemon list and then test to see if they are in view, then add them to a different list which can be used for the input.

Another option is to loop through the pokemon in view and then test to see if they are your pokemon.

Ex)

var/close_poke[0]
for(var/mob/pokemon/P in usr.pokemonlist)
if(P in oview(5, usr)) // Change 5 to whatever you want
close_poke += P
var/mob/Pokemon/P=input(usr,"Select a Pokemon to send out","Select") in close_poke
...


Edit:

You can use oview or view...depends on what you want. Look at the reference to figure out which one works best for you.
In response to Kalzar (#7)
I fixed it myself already, I finished up with this:
    Return()
set category = "PokeCommands"
for(var/mob/Pokemon/P in view(12)&&usr.pokemonlist)
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[P] Return!"
usr.PkmInInven+=1
return


Thanks to everyone who helped me out! I really appriciated it.
In response to Raimo (#8)
For this line:

for(var/mob/Pokemon/P in view(12)&&usr.pokemonlist)


I believe it should be oview?

view returns src.contents, oview does not.

Also should be & rather than &&.
I believe && adds view(12) and pokemonlist together and returns the results.
& operator


If A and B are lists, the result is a list that contains only items that were in both lists, in the order of list A.

----

A && B

The first false value from left to right completes the evaluation (a practice known as short-circuiting). The return value is equal to the last argument to be evaluated.
In response to Pirion (#9)
Oh, thank you. I didn't know that yet. Now I learned something more ^^.
Now at a new part, another runtime error popped up:
runtime error: Cannot modify null.cont.
proc name: Logout (/mob/Logout)
source file: world.dm,14
usr: Raimo (/mob/male1)
src: Raimo (/mob/male1)
call stack:
Raimo (/mob/male1): Logout()
Raimo (/client): Del()

The code:
mob
Logout()
src.overlays=null
world<<"<font color=silver><B><u>Server Information:</u></font> <font color=Red> [src] has disconnected from the server."
for(var/mob/Pokemon/P in world&&usr.pokemonlist)
if(P.returned==0&&P.owner==usr)
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
usr.PkmInInven+=1
continue
del(src)
..()


I'm not sure what's wrong as it works in the Return() verb.
Thanks to everyone who helps me.
In response to Raimo (#10)
By the time Logout() is called, the client is already gone.
In response to Garthor (#11)
Hmm, I see. Well, then I'm not sure how I would make it that when there is still a pokemon sent out when the player logout, it returns to their Bagpack(Inventory)? Something equal to:
    Return()
set category = "PokeCommands"
for(var/mob/Pokemon/P in oview(12)&usr.pokemonlist)
if(P.owner==usr&&P.returned==1)
usr<<"They are already in your bag!"
return
if(usr.PkmInInven==6)
usr << "You cant hold anymore pokemon in your pockets!"
return
else
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
client.cont=null
client.eye=usr
// Pmove=0
view(12) << "[usr]: [P] return!"
usr.PkmInInven+=1
return
In response to Raimo (#12)
Sorry for the double post. But I think I've managed it, instead of mob/Logout(), I used client/Del() which worked out pretty well.
client
Del()
for(var/mob/Pokemon/P in world&&usr.pokemonlist)
if(P.returned==0&&P.owner==usr)
walk(P,0)
P.loc=usr
P.returned=1
P.following=0
P.wandering=0
P.Training=0
P.contd2=1
usr.PkmInInven+=1
continue
..()


Thanks for all the help.
In response to Raimo (#13)
Using usr in Logout() or client/Del(), by the way, is an unbelievably unsafe thing to do. In this case, you should be using mob instead.

Also, if you're already looping through every mob in the world, why the hell are you bothering with the pokemonlist list?
In response to Garthor (#14)
Because the usr has to be the owner, and would you recommend me change it to src?
In response to Raimo (#15)
In response to Garthor (#16)
So any 'usr' in client/New() and client/Del() should be changed to 'mob'?
In response to Raimo (#17)
Raimo wrote:
So any 'usr' in client/New() and client/Del() should be changed to 'mob'?

I belive that's what he tried to say, yes.
In response to Darker Legends (#18)
Would it still have the same effect as I have now then?
Page: 1 2