ID:141479
 
Code:
mob
var
race
owner
selected
icon = 'player.dmi'
Login()
..()
world << "[src] has just entered '[world.name]'!"
verb
Start_New()
switch(input("Pick your race","Race Selection") in list("Human","Undead"))
if("Human")
new/mob/human (loc)
owner = M.client.key
if("Undead")
new/mob/skeleton (loc)
owner = M.client.key

human
icon = 'human.dmi'
name = "Human"
DblClick()
if (owner==src)
if (selected==0)
selected = 1
usr << "Human has been selected"
else
selected = 0
usr << "Human has been deselected"

turf
Click()
walk_to(usr,0)


Problem description:

error message:

Mob.dm:15:error:M.client.key:undefined var
Mob.dm:18:error:M.client.key:undefined var

kay so what im trying to do is have it so that when you create a unit with start_new() it will change the variable owner for the mob to your key, then if you double click a unit and it belongs to you, it becomes selected, then if you click on the turf it will take all the selected units and move them to a spot. i think im somewhat close in the beginning of this but by the moving to the spot im probably way off base. any help would be appreciated
M isn't defined in that code.
In response to Magicbeast20
kay... i put m as a variable in there but that didnt work, the error report says that the undefined variable is M.client.key not just M
In response to Netmanx
var/mob/human/M=new(loc)
//blah

...

var/mob/skeleton/M=new(loc)
//blah
In response to Kaiochao
mob
var
race
owner
selected
mob
human
M = new(loc)
skeleton
M = new(loc)
icon = 'player.dmi'
Login()
..()
world << "[src] has just entered '[world.name]'!"
verb
Start_New()
switch(input("Pick your race","Race Selection") in list("Human","Undead"))
if("Human")
new/mob/human (loc)
owner = M.client.key
if("Undead")
new/mob/skeleton (loc)
owner = M.client.key

could you please elaborate? i put it into where i think you were telling me to put it but i still get errors

Mob.dm:8:error:= :expected a constant expression
Mob.dm:10:error:M :duplicate definition
Mob.dm:8:error:M :previous definition
Mob.dm:10:error:= :expected a constant expression
In response to Netmanx
...In "selecting a unit," as the topic says.
In response to Kaiochao
no matter where i put it, its still giving me an error on var/mob/skeleton/M=new(loc)
In response to Netmanx
        Start_New()
switch(input("Pick your race","Race Selection") in list("Human","Undead"))
if("Human")
new/mob/human (loc) //There
owner = M.client.key
if("Undead")
new/mob/skeleton (loc) //and there.
owner = M.client.key
In response to Kaiochao
thanks, added that it,
i got to finish compiling and then i went to run it but when i selected my race i got this:

runtime error: Cannot read null.key
proc name: Start New (/mob/verb/Start_New)
source file: Mob.dm,16
usr: Netmanxxx (/mob)
src: Netmanxxx (/mob)
call stack:
Netmanxxx (/mob): Start New()

if youve any idea where i went wrong
In response to Netmanx
M is still not defined...
In response to Netmanx
You need to assign a value to M. If you just have
var/mob/M

then that is saying to the compiler, "I want to have a variable called M, that will hold a mob, but right now it doesn't contain anything."
It is not saying "I want to have a variable called M that contains a new /mob/human."
You have to put a reference to your mob in it:
var/mob/M
M = your mob

Or
var/mob/M = your mob

Obviously replacing "Your mob" with the mob you want it to refer to.
Hope that makes sense.
Your problem is here:
                if("Human")
new/mob/human (loc)
owner = M.client.key
if("Undead")
new/mob/skeleton (loc)
owner = M.client.key


I'll use the human as an example. The human you created is defined as human. So if you wanted to do anything with it put what its defined as, then its variable(Ie: human.owner). In your piece of code your changing the src(usr)'s owner to an unknown things key, since there is no M defined anywhere. I think what you want to do is set the human's owner to the src. To do this replace with your current code that is shown above.

                if("Human")
new/mob/human (loc)
human.owner = key//I think you would want it set to this or src
if("Undead")
new/mob/skeleton (loc)
skeleton.owner = key
In response to Bakasensei
mob
var
race
owner
selected
M
icon = 'player.dmi'
Login()
..()
world << "[src] has just entered '[world.name]'!"
verb
Start_New()
switch(input("Pick your race","Race Selection") in list("Human","Undead"))
if("Human")
new/mob/human (loc)
human.owner = key
if("Undead")
new/mob/skeleton (loc)
skeleton.owner = key

Mob.dm:16:error:human.owner:undefined var
Mob.dm:19:error:skeleton.owner:undefined var

ive tried to do the suggested but i dont really understand about giving M an actual value because i dont think its supposed to have a value? i have more than 1 mob using M so how could i assign M to a mob

i switched my code into the suggested with human.owner = key and such and that lowers the errors but now its saying its undefined but i really dont know how i would define it
In response to Netmanx
You really need to read the DM Guide and/or reference on this matter as you seem to not be getting what we're telling you. You should also read about typecasting here.
In response to Spunky_Girl
i did read through the gm guide and i get what variables are and such and how to use them but in dm it just doesnt seem to work the same as what i know, ill read through on typecasting
In response to Netmanx
I sure hope you read the bit on local variables too.
In response to Spunky_Girl
ill try but its not going incredibly well so far, i just dont get how i can type what looks to be the same thing but it will give me errors =(
In response to Netmanx
Here's an example of type casting a text-based variable.
mob/var/target = ""
mob/Click()
if(src != usr)
usr<<"You target [src]"
usr.target = src

mob/verb/Attack()
var/mob/T = src.target
if(!T || !(T in get_step(src,src.dir))) return
T.health -= rand(10,15)
viewers(T)<<"[T] was struck by [src]"


You type casted the target var to reference a specific mob in the world.
In response to Spunky_Girl
thanks for the example, ugh i just dont get it -_- i get the general idea of how it works it makes sense but i just cant get it to work for me heres what i got now:

mob
var
race
selected
M = ""
icon = 'player.dmi'
Login()
..()
world << "[src] has just entered '[world.name]'!"
verb
Start_New()
switch(input("Pick your race","Race Selection") in list("Human","Undead"))
if("Human")
new/mob/human (loc)
human.owner = client.key


human
icon = 'human.dmi'
name = "Human"
DblClick()
if (human.owner==client.key)
if (selected==0)
selected = 1
usr << "Human has been selected"
else
selected = 0
usr << "Human has been deselected"


am i any closer to getting this right? im getting the following errors.

Mob.dm:15:error:human.owner:undefined var
Mob.dm:47:error:human.owner:undefined var

im trying to define them and i think the way its supposed to go is that owner is a variable contained within the mob human but thats not how its looking
In response to Netmanx
My Click() proc was just an example on how to set the target var. Not something you have to do. And you don't seem to get what type casting is. Type casting is something you do locally, so only done in verbs/procs pretty much.

What you're not doing, is giving the var a type when you attempt to type cast.
mob/var
M

//logically, mob/var/M != mob/M
var/mob/N = M //this is logically correct
Page: 1 2