ID:1622221
 
(See the best response by Jittai.)
Code:
mob
Merchant
icon = 'NPCs.dmi'
icon_state = "Clothing"
name = "{NPC}Merchant"
npc = 1
verb
Talk()
set category = "NPC's"
set src in oview(2)
switch(input("Yo sup, wanna buy some clothes?", text) in list ("Yes","No"))
if("Yes")
switch(input("What do you want to buy?", text) in list ("BlackMask","DarkRedMask","GreenMask","GreyMask","OrangeMask","PurpleMask","RedMask","WhiteMask","Ninja Suit","Flower Cloak"))
if("BlackMask")
var/K = new/obj/BlackMask
K:loc = usr
usr << "<b>Have a nice day!"
if("DarkRedMask")
var/K = new/obj/DarkRedMask
K:loc = usr
usr << "<b>Have a nice day!"
if("GreenMask")
var/K = new/obj/GreenMask
K:loc = usr
usr << "<b>Have a nice day!"
if("GreyMask")
var/K = new/obj/GreyMask
K:loc = usr
usr << "<b>Have a nice day!"
if("OrangeMask")
var/K = new/obj/OrangeMask
K:loc = usr
usr << "<b>Have a nice day!"
if("PurpleMask")
var/K = new/obj/PurpleMask
K:loc = usr
usr << "<b>Have a nice day!"
if("RedMask")
var/K = new/obj/RedMask
K:loc = usr
usr << "<b>Have a nice day!"
if("WhiteMask")
var/K = new/obj/WhiteMask
K:loc = usr
usr << "<b>Have a nice day!"
if("Flower Cloak")
var/K = new/obj/flowercloak
K:loc = usr
usr << "<b>Have a nice day!"
if("Ninja Suit")
var/K = new/obj/ninja
K:loc = usr
usr << "<b>Have a nice day!"

Problem description:



And I keep getting this once I press compile:

Codes\Mob.dm:403:error: /obj/BlackMask: undefined type path
Codes\Mob.dm:407:error: /obj/DarkRedMask: undefined type path
Codes\Mob.dm:411:error: /obj/GreenMask: undefined type path
Codes\Mob.dm:415:error: /obj/GreyMask: undefined type path
Codes\Mob.dm:419:error: /obj/OrangeMask: undefined type path
Codes\Mob.dm:423:error: /obj/PurpleMask: undefined type path
Codes\Mob.dm:427:error: /obj/RedMask: undefined type path
Codes\Mob.dm:431:error: /obj/WhiteMask: undefined type path


The errors are accurate, the type paths are not defined for those objects.
where could i find out how to define them properly?
The issue is those objects aren't actually "defined" - and to deifne something you need to write out the path and tell (define) it's vars/verbs/behavior under it's path.

I.e: /mob/Merchant/ is defined because you wrote out it's path (and also stuck vars and verbs under it).


There's a lot of sloppy technique going on, if you're interested. You should always look at your code and see what repeats and what can be cut down.

For one the masks should be under the same path like "/obj/Mask/Black". This can cut down on a lot of potential shared verbs/procs like equip/wear behaviors.

If you define K before the bunch of if()'s as simply "var/obj/Mask/K = null" You can cut down on a lot of repeating code and just have: "if("Ninja Suit") K = new/obj/Mask/ninja" for each mask type.

You'd only have to write "K.loc = usr" and the message once and just indent it with the if()s - and you'd get rid of the colon usage as a bonus.


Just as a pet peeve you could also unindent a lot of the switch stuff uptop. If you use a return and an if to check for "No" and return if so.


Once you get rid of all those issues, you could look for creative things that cut down on managing the code like using text2path() or typesof() so that you only have to edit one list instead of spamming if()s.
In response to Jittai
Jittai wrote:
You'd only have to write "K.loc = usr" and the message once and just indent it with the if()s - and you'd get rid of the colon usage as a bonus.

And, if the only reason why you need a variable is to define the location, you can get rid of it by doing: new/item/path(location)

Ex:
new/obj/TheMask(usr)
alright, i think i understand it alot more
actually, could one of you guys please possibly put the all of the code together in the way you are explaining it? i dont mean to make you guys give me the answer, i just dont completely understand where im supposed to be replacing things
that your telling me with what i had. From my perspective, you guys want me to do this:

mob
Merchant
icon = 'NPCs.dmi'
icon_state = "Clothing"
name = "{NPC}Merchant"
npc = 1
verb
Talk()
set category = "NPC's"
set src in oview(2)
switch(input("Yo sup, wanna buy some clothes?", text) in list ("Yes","No"))
if("Yes")
switch(input("What do you want to buy?", text) in list ("BlackMask","DarkRedMask","GreenMask","GreyMask","OrangeMask","PurpleMask","RedMask","WhiteMask","Ninja Suit","Flower Cloak"))
if("BlackMask")
var/K = new/obj/Mask/Black
K:loc = usr
usr << "<b>Have a nice day!"
if("DarkRedMask")
var/K = new/obj/Mask/DarkRedMask
K:loc = usr
usr << "<b>Have a nice day!"
if("GreenMask")
var/K = new/obj/Mask/Green
K:loc = usr
usr << "<b>Have a nice day!"
if("GreyMask")
var/K = new/obj/Mask/Grey
K:loc = usr
usr << "<b>Have a nice day!"
if("OrangeMask")
var/K = new/obj/Mask/Orange
K:loc = usr
usr << "<b>Have a nice day!"
if("PurpleMask")
var/K = new/obj/Mask/Purple
K:loc = usr
usr << "<b>Have a nice day!"
if("RedMask")
var/K = new/obj/Mask/Red
K:loc = usr
usr << "<b>Have a nice day!"
if("WhiteMask")
var/K = new/obj/Mask/White
K:loc = usr
usr << "<b>Have a nice day!"
if("Flower Cloak")
var/K = new/obj/Mask/FlowerCloak
K:loc = usr
usr << "<b>Have a nice day!"
if("Ninja Suit")
var/K = new/obj/Mask/Ninja
K:loc = usr
usr << "<b>Have a nice day!"



but then i get:

Codes\Mob.dm:403:error: /obj/Mask/Black: undefined type path
Codes\Mob.dm:407:error: /obj/Mask/DarkRedMask: undefined type path
Codes\Mob.dm:411:error: /obj/Mask/Green: undefined type path
Codes\Mob.dm:415:error: /obj/Mask/Grey: undefined type path
Codes\Mob.dm:419:error: /obj/Mask/Orange: undefined type path
Codes\Mob.dm:423:error: /obj/Mask/Purple: undefined type path
Codes\Mob.dm:427:error: /obj/Mask/Red: undefined type path
Codes\Mob.dm:431:error: /obj/Mask/White: undefined type path
Codes\Mob.dm:435:error: /obj/Mask/FlowerCloak: undefined type path
Codes\Mob.dm:439:error: /obj/Mask/Ninja: undefined type path
What Ter13 was trying to point out was that at the very least, you need to have those type paths defined somewhere in your code:
obj
Mask
Black
DarkRedMask
Green
Grey
Orange
Purple
Red
White
FlowerCloak
Ninja

DM cannot create new types for you at runtime. They must be defined before you can use them.

Also, if those paths only exist because you want objects with different icons, then you are not programming correctly. New type paths should only be defined for objects with different behaviors.
You're misunderstanding the indentions thing as well as the crucial cut down on repetitive text. Your code should only have 1 "K:loc = usr" and 1 "usr << "Have a nice day!" " in the whole code.

As for the switch/if and returning.

if((input("Yo sup, wanna buy some clothes?", text) in list ("Yes","No"))=="No") return


This allows you to have the rest of the code without having it all indented under it.
Back to what Multiverse7 said. i added that and it compiled without any errors but now in game when i buy a mask ingame and go into my inventory, its there but theres not "wear" verb
and no icon. also, multiverse, the code you gave me i did not put directly under the code about the masks that i had
In response to RicoTheCreator
Are you saying you defined masks somewhere before you made this topic? If so, you should show that code too.
Do you have a wear verb?
ya i do have a wear verb and it worked but since i added:
obj
Mask
Black
DarkRedMask
Green
Grey
Orange
Purple
Red
White
FlowerCloak
Ninja



it no longer works in-game
Any help?
Well, there's no good reason why just defining new object types would break your verb.

Show us the wear verb, and maybe we can help you.
not sure why but, the wear verb in-game did work before but i double checked my code and it appears that i do not have one.. there would the appropriate place be to put it?

mob
Merchant
icon = 'NPCs.dmi'
icon_state = "Clothing"
name = "{NPC}Merchant"
npc = 1
verb
Talk()
set category = "NPC's"
set src in oview(2)
switch(input("Yo sup, wanna buy some clothes?", text) in list ("Yes","No"))
if("Yes")
switch(input("What do you want to buy?", text) in list ("Black","DarkRedMask","GreenMask","GreyMask","OrangeMask","PurpleMask","RedMask","WhiteMask","Ninja Suit","Flower Cloak"))
if("Black")
var/K = new/obj/Mask/Black
K:loc = usr
usr << "<b>Have a nice day!"
if("DarkRedMask")
var/K = new/obj/Mask/DarkRedMask
K:loc = usr
usr << "<b>Have a nice day!"
if("GreenMask")
var/K = new/obj/Mask/Green
K:loc = usr
usr << "<b>Have a nice day!"
if("GreyMask")
var/K = new/obj/Mask/Grey
K:loc = usr
usr << "<b>Have a nice day!"
if("OrangeMask")
var/K = new/obj/Mask/Orange
K:loc = usr
usr << "<b>Have a nice day!"
if("PurpleMask")
var/K = new/obj/Mask/Purple
K:loc = usr
usr << "<b>Have a nice day!"
if("RedMask")
var/K = new/obj/Mask/Red
K:loc = usr
usr << "<b>Have a nice day!"
if("WhiteMask")
var/K = new/obj/Mask/White
K:loc = usr
usr << "<b>Have a nice day!"
if("Flower Cloak")
var/K = new/obj/Mask/FlowerCloak
K:loc = usr
usr << "<b>Have a nice day!"
if("Ninja Suit")
var/K = new/obj/Mask/Ninja
K:loc = usr
usr << "<b>Have a nice day!"
Are you sure you haven't lost some of your source files somewhere?

Basically you just need to define it right under /obj/Mask:
obj
Mask
verb
Wear()
usr << "You wear [src]."
ok, the verb now works but not the icon.

obj
Mask
Black
DarkRedMask
Green
Grey
Orange
Purple
Red
White
FlowerCloak
Ninja

obj
Mask
verb
Wear()
usr << "You wear [src]."
In response to RicoTheCreator
RicoTheCreator wrote:
ok, the verb now works but not the icon.

Did you expect the icons to code themselves?
You have to define those too.

For example:
obj
Mask
icon = 'Mask.dmi'
New()
..()
icon_state = "[name]"
Page: 1 2