ID:146192
 
Code:

                    var/obj/O
for(O in usr)
usr << "[O.name]"
if (O.name == "log")
var/obj/O1
for(O1 in usr)
if (O1.name == "saw")
new /obj/board(usr)
new /obj/woodchips(usr)
usr << "You have successfully made a board!"
del O
return 1
if(!usr.contents.Find(/obj/saw))
usr<<browse("<font color=#666666 face=Times New Roman size=3>Buy a saw.</font>","window=Allarkis")
return
if(!usr.contents.Find(/obj/log))
usr<<browse("<font color=#666666 face=Times New Roman size=3>Buy a log.</font>","window=Allarkis")
return


Problem description: If you ignore the two if statements at the bottom that generate browse statements telling you what is missing from your attempt at making lumber, the above code will work. However, I need the code to show the user what he is missing. I have set up the verb to for list the contents of the user so that if the items are present, the board is automatically made. I do not know how to make it do the browse statments when it is done looping the list.

The chain of thought in this code should be...
check user's inventory
is there a log?
Yes, there is a log
is there a saw?
Yes, there is a saw
give user a board
give user some woodchips
destroy the log
end the verb
No, there is no saw in the user's entire inv.
tell user to buy a saw
end the verb
No, there is no log in the user's entire inv.
tell user to buy a log
end the verb

I assumed you wanted something like this. It can be easily customizeable.
mob/verb/Make_Board() 
var/obj/LOG
var/SAW
for(var/obj/O in src) if(istype(O,/obj/Log/)) LOG=O
//Checks type, Sets the object to LOG, Reduces future loops
for(var/obj/O in src) if(istype(O,/obj/Saw/)) SAW=1
//Checks type, Sets SAW to true
if(LOG&&SAW)
new /obj/board(usr)
new /obj/woodchips(usr)
src << "You have successfully made a board!"
del(LOG)
if(!SAW) src<<"Buy a saw."
if(!LOG) src<<"Buy a log."
In response to CaptFalcon33035
CaptFalcon33035 wrote:
I assumed you wanted something like this. It can be easily customizeable.
> mob/verb/Make_Board() 
> var/obj/LOG
> var/SAW
> for(var/obj/O in src) if(istype(O,/obj/Log/)) LOG=O
> //Checks type, Sets the object to LOG, Reduces future loops
> for(var/obj/O in src) if(istype(O,/obj/Saw/)) SAW=1
> //Checks type, Sets SAW to true
> if(LOG&&SAW)
> new /obj/board(usr)
> new /obj/woodchips(usr)
> src << "You have successfully made a board!"
> del(LOG)
> if(!SAW) src<<"Buy a saw."
> if(!LOG) src<<"Buy a log."
>

Thank you VERY much for the help mate. All I had to change was "var/obj/SAW" and (O,/obj/log) and (O,/obj/saw).

I really hate bugging people for help on something that SHOULD be so simple (is simple, sorry). Any chance you can explain why this works and mine doesn't? 8)
In response to Kidknee
Yes, I will do so if you please. You have a loop inside of a loop, and if one loop isn't accessible, the other won't function, either. You check for a log, and if you have one, you loop through the contents for a saw, and if you don't have a log, it won't check for the saw.

Also, that process can create a lot of lag, or spam at least, if you multiple logs and a saw or two. Also, if you do not have any logs, you will be spammed in the browser with a message stating that you do not have a log because it is in the loop.

Mine works because it checks for the object one at a time, using two seperate loops. You may be able to use one loop, but I believe you'd have to have continue somewhere in there.

Anyway, my process checks for the exact type, so there happens to be no errors, having to do with objects accidentally named a log.

If you have both the log and the saw, it creates your wood chips, and if you're missing either, it alerts you of this error.

As for setting the SAW variable to an object, it's not neccessary. If you aren't going to access the SAW as an object later on in the code, you don't need it. It reduces lag and space (I suppose). I accessed the log as an object variable because if the user happens to have the log, I can delete the variable, that will be taking the log with it instead of cycling through the list again and finding the log.
In response to CaptFalcon33035
I have taken your example and set it up to do a "Forge_Iron" verb. Initially, I had it set up to use only hematite ore. I decided I wanted it to allow the tradeskiller to use either small, medium, or large bits of hematite ore. No matter what size ore the user used, it would cost him one charcoal and the piece of ore. However, with the three sizes, the size of the piece used determines how many pieces of iron you get as the end result. A small ore makes 1 iron piece, a medium makes 3 and a large makes 5. I have tried various ways to implement this, and every time I have gotten odd results. How would you change this to allow the user to pick which type of ore (by size in this case) is used, and then have it delete ONLY that piece of ore AND make the correct amount of iron pieces?

Forge_Iron()
set category = "Trade Skills"
if(!usr.verbs.Find(/obj/verbbox/verb/Blacksmithing))
usr<<browse("<font color=#666666 face=Times New Roman size=3>You don't know the first thing about Carpentry. Find a trainer.</font>","window=Allarkis")
return
if(usr.verbs.Find(/obj/verbbox/verb/Blacksmithing))
var/obj/CHARCOAL
var/obj/HEMATITE
var/obj/HAMMER
var/obj/ANVIL
var/obj/TONGS
var/obj/FORGE
for(var/obj/O in src) if(istype(O,/obj/charcoal/)) CHARCOAL=O
for(var/obj/O in src) if(istype(O,/obj/hematite/smallhematiteore/)||istype(O,/obj/hematite/mediumhematiteore/)||istype(O,/obj/hematite/largehematiteore/)) HEMATITE=O
for(var/obj/O in src) if(istype(O,/obj/hammer/)) HAMMER=1
for(var/obj/O in src) if(istype(O,/obj/anvil/)) ANVIL=1
for(var/obj/O in src) if(istype(O,/obj/tongs/)) TONGS=1
for(var/obj/O in src) if(istype(O,/obj/forge/)) FORGE=1
if(!HEMATITE) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have a piece of hematite to heat in the forge. Go buy one.</font>","window=Allarkis")
if(!CHARCOAL) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have charcoal to burn in the forge. Go buy some.</font>","window=Allarkis")
if(!HAMMER) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have a hammer to work hit the heated ore with. Go buy one.</font>","window=Allarkis")
if(!ANVIL) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have an anvil on which to hammer the ore. Go buy one.</font>","window=Allarkis")
if(!TONGS) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have tongs to hold the heated ore. Go buy some.</font>","window=Allarkis")
if(!FORGE) usr<<browse("<font color=#666666 face=Times New Roman size=3>You must have a forge in which to heat the ore. Go buy one.</font>","window=Allarkis")
if(CHARCOAL&&HEMATITE&&HAMMER&&ANVIL&&TONGS&&FORGE)
del(HEMATITE)
del(CHARCOAL)
src << "You have successfully made a bit of iron!"

In response to Kidknee
You might've started a new thread for this, but, you can use object grouping. That is, make a stat for an object a user has, or an objects suffix. When the user picks up the item, if he has one of the same type, add one to the suffix. When the item is dropped or deleted, check to see if he has any more of the item, or enough. If he doesn't have any more of the item, delete it from the inventory.