ID:255361
 
(See the best response by DarkCampainger.)
for(var/obj/Mining/Copper_Ore/A in usr.contents && var/obj/Mining/Tin_Ore/B)
if(A in usr.contents)
if(B in usr.contents)

obj
Furnace
icon='Ore.dmi'
icon_state="furnace"
density=1
Click()
if(src in range(1))
switch(input("Which type of bar would you like to make?","Options")in list("Bronze","Iron","Steel","Cancel"))
if("Bronze")
for(var/obj/Mining/Copper_Ore/A in usr.contents && var/obj/Mining/Tin_Ore/B)
if(A in usr.contents)
if(B in usr.contents)
if(usr.SmithLV>=0) //can we cut it?
if(usr.Active==0) //are we doing anything?
if(!src.beingsmithed)//if tree being cut?
usr.Frozen=1
usr.Active=1
src.beingsmithed=1
del(A)
del(B)
usr << "You begin smeltingthe [src]"
flick("smithing",usr)//make this match
// A.loc=usr.loc
//flick("cutting",A)
// loc = usr.contents
src.icon_state="smelting"
sleep(15)
usr.SmithXP+=6
usr.SmithLevelCheck()
src.icon_state="furnace"
src.beingsmithed=0
usr.Active=0
usr.Frozen=0
usr.contents += new /obj/Bar/Bronze



I'm checking to see if usr has these items in their inventory... however, it even if they do nothing happens. THe best i've been able to do is get it to work when only having A, but when A|B are both present, it does not work.

Suggestions?

Best response
&& is a logical operator. It takes the value to its left, and the value to its right, and returns true* if both values are true, or false otherwise.

There is no special syntax for a for() loop that allows you to loop through two types at once.

However, you don't actually want a for() loop. You aren't looping through all of the Copper_Ore in the player's contents. You just want to locate one instance of it in the player's contents:

var/obj/Mining/Copper_Ore/A = locate() in usr.contents
var/obj/Mining/Tin_Ore/B = locate() in usr.contents
if(A && B) // If both Copper and Tin were located
// Do stuff!



*It technically returns the value to its right
Ah i understand now!

Brilliant it works, thanks!