ID:159313
 
Hello there, im a newbie when it comes to programming and i am stuck on something, im trying to make a stove to cook things in, basically what i have come up with to now is that when u use the "cook" verb i want the stove to check for the neccesary ingredients in the users inventory.

- im sure its simple but i cant find a good way to do it..
here is what i have done.
verb
cook()
set category = "test"
set src in oview(1)
switch(input("what do you want to cook?", text) in list("rabbit stew","Chicken"))
if("rabbit stew")
if(usr.rMeat >=1)
usr << "you start making rabbit stew"
sleep(5)
usr.contents += new/obj/food/stew
usr.rMeat -=1
for(var/obj/food/rMeat in usr.contents)
if(rMeat)
usr.contents -= /obj/food/rMeat
else
usr <<"you do not have the neccesary ingrediends"
return

its messy i know :P

anyways, it fails to remove rMeat from the usr.contents. i tryed making :(instead of what is above)

var/obj/food/rMeat/R

and then
for(var/obj/food/R in usr.contents)
if(R)
del(R)

this however leads to all the rMeat in the inventory to be deleted, i need it to only delete one .

hope anyone can help or point me in the right direction.

Best regards

Zeppo

Try something like.

var/obj/O = locate(/obj/food/rMeat) in usr.contents

Then use if(O) to see if it found it.
In response to Lundex
wow, that was fast xD, ill try that.
In response to Zeppo
Also, using the for() will loop and check if rMeat is in usr.contents, and if there is one. It will delete it.
In response to Lundex
i get a warning upon compileing :

O: variable defined but not used.
for(var/obj/O = locate(/obj/food/rMeat) in usr.contents)
if(O)
usr.contents -= /obj/food/


i might have misunderstood you .. was it ths you meant?
In response to Zeppo
mob/verb
Cook()
switch(input("What do you want to cook?") in list("Rabbit Stew", "Chicken"))
if("Rabbit Stew")
var/I
for(var/obj/food/food in usr.contents)
if(istype(food, /obj/food/rMeat))
I++
if(I)
usr << "You start making Rabbit Stew"
sleep(5)
usr << "You finish the stew."
usr.contents += new /obj/food/stew
usr.contents -= locate(/obj/food/rMeat) in usr.contents
else
usr << "You don't have any meat for Rabbit Stew."


Something like this. And this is not the only way to do it.
In response to Lundex
that worked perfectly lundex!!!

many great kisses and hugs to you :D thank you
In response to Zeppo
Uhhh, no need for the kisses and hugs. Just basic stuff.
This sort of thing is a perfect candidate to start learning how to utilize the object-oriented aspects of programming languages.

In your case, you have a recipe of some sort (ingredient requirements to cook something). The player doesn't actually have a recipe, but you have a very clear idea as the developer on what the player needs to cook something.

So why not create a datum, to store that information? You can store what ingredients a recipe takes, what the recipe is called, and what is produced. This would even allow you to vary the result based on the quality of ingredients. Datums are good to look into any time you need to group information together, like in the case of guilds, groups, chat channels, etc.

Heres an example of how the recipe datum might look like:

recipe
var
name=""
list/ingredients
list/results

proc
Make(mob/M)
var/list/remove=list()
for(var/a in ingredients)
var/amount = 0
for(var/obj/O in M.contents)
if(istype(O, text2path(a))
amount += 1
remove += O
if(amount < ingredients[a]) return 0

M.contents.Remove(remove)

for(var/a in results)
var/p = text2path(a)
var/amount = results[a]
while(amount--)
var/atom/A = new p()
if(isobj(A)) A.Move(M)
else if(ismob(A)) A.Move(M.loc)



/recipe isn't an actual, physical thing in the game. Its a collection of information and procedures; the Make() procedure goes through three steps:

1) Does the mob passed to Make() have the ingredients that I require?
2) Remove the ingredients from the mobs inventory
3) Give the mob the resulting items

A recipe might look like so:

recipe/rabbit_stew
name = "Rabbit Stew"
ingredients = list("/obj/rmeat" = 3)
results = list("/obj/rabbit_stew" = 1)


The rabbit stew requires 3 /obj/rmeat, and gives the player 1 /obj/rabbit_stew.

The next step after this then, is how do you work this into your verbs? Well, I'd suggest storing a list of recipes in a global list and creating them on world/New():

var/list/recipes=list()
world/New()
..()
for(var/a in typesof(/recipe) - /recipe)
var/recipe/R = new a()
recipes += R


Then you can loop through the recipes list, grab the name of every recipe, ask the player which name they want to make, then check back through the recipes list for the one with that name - And call Make().
In response to Lundex
Lundex wrote:
Uhhh, no need for the kisses and hugs. Just basic stuff.

Yeah cut the crap, he wants the good stuff. ;)
In response to Alathon
Alathon wrote:
This sort of thing is a perfect candidate to start learning how to utilize the object-oriented aspects of programming languages.

In your case, you have a recipe of some sort (ingredient requirements to cook something). The player doesn't actually have a recipe, but you have a very clear idea as the developer on what the player needs to cook something.

So why not create a datum, to store that information? You can store what ingredients a recipe takes, what the recipe is called, and what is produced. This would even allow you to vary the result based on the quality of ingredients. Datums are good to look into any time you need to group information together, like in the case of guilds, groups, chat channels, etc.

Heres an example of how the recipe datum might look like:

> recipe
> var
> name=""
> list/ingredients
> list/results
>
> proc
> Make(mob/M)
> var/list/remove=list()
> for(var/a in ingredients)
> var/amount = 0
> for(var/obj/O in M.contents)
> if(istype(O, text2path(a))
> amount += 1
> remove += O
> if(amount < ingredients[a]) return 0
>
> M.contents.Remove(remove)
>
> for(var/a in results)
> var/p = text2path(a)
> var/amount = results[a]
> while(amount--)
> var/atom/A = new p()
> if(isobj(A)) A.Move(M)
> else if(ismob(A)) A.Move(M.loc)
>
>
>
>

/recipe isn't an actual, physical thing in the game. Its a collection of information and procedures; the Make() procedure goes through three steps:

1) Does the mob passed to Make() have the ingredients that I require?
2) Remove the ingredients from the mobs inventory
3) Give the mob the resulting items

A recipe might look like so:

> recipe/rabbit_stew
> name = "Rabbit Stew"
> ingredients = list("/obj/rmeat" = 3)
> results = list("/obj/rabbit_stew" = 1)
>

The rabbit stew requires 3 /obj/rmeat, and gives the player 1 /obj/rabbit_stew.

The next step after this then, is how do you work this into your verbs? Well, I'd suggest storing a list of recipes in a global list and creating them on world/New():

> var/list/recipes=list()
> world/New()
> ..()
> for(var/a in typesof(/recipe) - /recipe)
> var/recipe/R = new a()
> recipes += R
>

Then you can loop through the recipes list, grab the name of every recipe, ask the player which name they want to make, then check back through the recipes list for the one with that name - And call Make().


I would just like to state this. This datum will be very useful for many different types of things.

Thanks Alathon.
In response to Alathon
Alathon wrote:
This sort of thing is a perfect candidate to start learning how to utilize the object-oriented aspects of programming languages.

In your case, you have a recipe of some sort (ingredient requirements to cook something). The player doesn't actually have a recipe, but you have a very clear idea as the developer on what the player needs to cook something.

So why not create a datum, to store that information? You can store what ingredients a recipe takes, what the recipe is called, and what is produced. This would even allow you to vary the result based on the quality of ingredients. Datums are good to look into any time you need to group information together, like in the case of guilds, groups, chat channels, etc.

Heres an example of how the recipe datum might look like:

> recipe
> var
> name=""
> list/ingredients
> list/results
>
> proc
> Make(mob/M)
> var/list/remove=list()
> for(var/a in ingredients)
> var/amount = 0
> for(var/obj/O in M.contents)
> if(istype(O, text2path(a))
> amount += 1
> remove += O
> if(amount < ingredients[a]) return 0
>
> M.contents.Remove(remove)
>
> for(var/a in results)
> var/p = text2path(a)
> var/amount = results[a]
> while(amount--)
> var/atom/A = new p()
> if(isobj(A)) A.Move(M)
> else if(ismob(A)) A.Move(M.loc)
>
>
>
>

/recipe isn't an actual, physical thing in the game. Its a collection of information and procedures; the Make() procedure goes through three steps:

1) Does the mob passed to Make() have the ingredients that I require?
2) Remove the ingredients from the mobs inventory
3) Give the mob the resulting items

A recipe might look like so:

> recipe/rabbit_stew
> name = "Rabbit Stew"
> ingredients = list("/obj/rmeat" = 3)
> results = list("/obj/rabbit_stew" = 1)
>

The rabbit stew requires 3 /obj/rmeat, and gives the player 1 /obj/rabbit_stew.

The next step after this then, is how do you work this into your verbs? Well, I'd suggest storing a list of recipes in a global list and creating them on world/New():

> var/list/recipes=list()
> world/New()
> ..()
> for(var/a in typesof(/recipe) - /recipe)
> var/recipe/R = new a()
> recipes += R
>

Then you can loop through the recipes list, grab the name of every recipe, ask the player which name they want to make, then check back through the recipes list for the one with that name - And call Make().

this was really good and helpfull, thanks alot.. i havent even thought about something like that xD