ID:166681
 
here is my code below, so far it checks to see if you atleast have a bar in your inventory. But i need it to check to see if you have 2 bars to make a dagger. I've tryed alot of diffrent things((bars>=2),(/obj/bronzebar>=2) and even setting the var/bars as a number)but i always get a runtime, mostly type mismatch. How can i make it so you need 2 bars or more to make a dagger?
            Smith()
set src in oview(1)
var/check=input("What type of bar do you wish to smith?") in list ("Bronze","Cheese")
if(check=="Bronze")
var/obj/bronze= locate(/obj/bronzebar) in usr.contents
if(bronze)
var/smith=input("What would you like to smith") in list ("Dagger","Sword","Bigsword","Battleaxe","Claws")
if(smith=="Dagger")
var/obj/bars = locate(/obj/bronzebar) in usr.contents
if(bars)
usr<<"You begin to hammer out a bronze dagger!"
sleep(20)
del(bars)
usr.contents+=new/obj/weapons/Bronze_Dagger
usr<<"You made a bronze dagger!"
else
usr<<"You do not have enough bars!"


this is my first game, and my first time coding one. Plz help
FriesOfDoom wrote:
here is my code below, so far it checks to see if you atleast have a bar in your inventory. But i need it to check to see if you have 2 bars to make a dagger. I've tryed alot of diffrent things((bars>=2),(/obj/bronzebar>=2) and even setting the var/bars as a number)but i always get a runtime, mostly type mismatch. How can i make it so you need 2 bars or more to make a dagger?
>           Smith()
> set src in oview(1)
> var/check=input("What type of bar do you wish to smith?") in list ("Bronze","Cheese")
> if(check=="Bronze")
> var/obj/bronze= locate(/obj/bronzebar) in usr.contents
> if(bronze)
> var/smith=input("What would you like to smith") in list ("Dagger","Sword","Bigsword","Battleaxe","Claws")
> if(smith=="Dagger")
> var/obj/bars = locate(/obj/bronzebar) in usr.contents
> if(bars)
> usr<<"You begin to hammer out a bronze dagger!"
> sleep(20)
> del(bars)
> usr.contents+=new/obj/weapons/Bronze_Dagger
> usr<<"You made a bronze dagger!"
> else
> usr<<"You do not have enough bars!"
>

<font color=red>this is my first game, and my first time coding one.</font> Plz help

In this case, the thing to understand is that locate() always returns the very first object it can find: it doesn't care about how many objects are in the location it's looking in, as long as it has at least one.

What you're going to need to do here is make a couple of loops: you have to step through every object in the player's inventory to see how many bars the player has, and then if the player has enough bars, you have to remove the bars you find.

Basically, your code is doing this:

ask for the metal object the player wants to use to smelt with
if the player has any of that object,
find the type of object the player wants to smelt
if the player has one object of smelting material,
delete the smelting material
smelt the object
otherwise
inform the player of failure


What you need to do is find a list of all of the bars in the player's inventory, and then delete those objects one by one if the player has enough of them.

This works something like this:

ask for the metal type the player wants to smelt with
if the player has any objects whose 'type' matches that type
find the type of object the player wants to smelt
make a list: var/list/smelting_material = list()
run through the inventory from start to finish: for(var/obj/O in contents)
if the object matches the type you are looking for,
add it to the smelting material list
if the smelting material list's length is at least as big as the material we need
'break' out of the loop
if smelting_material.len >= bars needed
define a temporary variable = 0
run through the smelting material list: for(var/obj/O in smelting_material)
delete the object
set temporary variable to temporary variable + 1
if temporary variable >= bars needed
'break' out of the loop
smelt the object
else
inform the player of failure