ID:262017
 
proc
new_recipe()
var/obj/recipe/N = new()
N.recname = input("What is the recipe's name?")
N.ingredients = input("What is in the recipe?")
for(N.ingredients)
N.ing="<li>[N.ingredients]"
N.yield = input("How much does this recipe yield?") as num
N.directions = input("What do you do?") as message
usr<< browse({"
<html>
<table>
<tr><td>
Name:
[N.recname]
</tr></td>
<tr><td>
Ingredients:
[N.ing]
</tr></td>
<tr><td>
Directions:<pre>
[N.directions]</pre><dm>
</tr></td>
<tr><td>
Yield:
[N.yield]
</tr></td>
</html>"}
)
RecList+=N.recname
world << RecList //check the RecList


mob
verb
new_rec()
new_recipe()
find_rec(t as text)
if(findtext(RecList,t))
world<< "Found"
else
world<< "0"

obj
recipe
var
recname as text
ingredients = list()
directions
yield as num
ing

var
RecList = list()

I have no errors show up, but I do have some problems.

1. The ingredients has a bullet, but it prints out as "The recipe" every time, no matter what.

2. RecList always comes up as "/list". I guess that the recname is adding?

3. Because RecList is "/list", the Find_rec always returns zero, because the recipe name isn't in the list it checks!

The following part is realated, but may not be for this forum, but I thought it should be because of the problems stated above.

This is a database application that I am attempting to create. As of now, I am trying to create a database of recipes. I have worked with savefiles very little, and while trying to figure out how to do the following, I got no where.

I want to be able to store all the variables of the recipe object, either in one savefile, seperated so I can get each recipe alone, or in many savefiles. That way, when the find_rec verb is processed, it gathers all the vars and creates a page just like the one seen when you create a recipe entry.
Don't use usr in procs.
In response to Garthor
Thanks for the tip, but will it fix my problem?

As far as using src, I can't seem to get it to work. I added:
set src = usr


But it didn't show anything when I changed usr to src before the "<< browse()". I add the set right under new_recipe().
Odd... I added an icon to the obj "recipe" and when I click it it brings up the proc new_recipe, but now in the ingredients, instead of "The recipe" (which isn't supposed to happen either) it says "The turf" all I did was add

icon = 'New Recipe.dmi'
and
Click()
new_recipe()
In response to Dragon of Ice
Dragon of Ice wrote:
Thanks for the tip, but will it fix my problem?

As far as using src, I can't seem to get it to work. I added:
set src = usr

But it didn't show anything when I changed usr to src before the "<< browse()". I add the set right under new_recipe().

You don't need to be using src there either. Globally defined procs most likely don't have a default 'src', and if they do, I'm sure it isn't going to be what you want it to be there. You should be passing an argument to the proc and using that. When you define your proc, define it as 'proc/new_recipe(mob/M)', and when you call the proc, call 'new_recipe(src)', or 'new_recipe(usr)' if you are calling it from a verb, and not from another proc. Then use 'M << browse(stuff)' and you will know exactly who M is.

I'll check your original post in a minute.

Dragon of Ice wrote:

1. The ingredients has a bullet, but it prints out as "The recipe" every time, no matter what.

When the input comes up asking you 'What is the recipe?', are you typing in 'The Recipe'? Essentially, you are setting the var N.ingredients equal to whatever you type in as the answer to that question. If you want to create a list of ingredients, you'll need to set that up quite a bit differently. Something like this would work:
var/finished = FALSE
while(!finished)
var/newIngredient = input(M, "Enter a new ingredient for your recipe. Press 'Cancel' to finish.", "Enter ingredient") as null|text
if(newIngredient)
N.ingredients += newIngredient
else
finished = TRUE


2. RecList always comes up as "/list". I guess that the recname is adding?

Whenever you output a list var to a mob or client, the output simply shows up as '/list'. If you want to show all the elements in the list, you need to cycle through them individually.
for(var/V in RecList)
M << V


3. Because RecList is "/list", the Find_rec always returns zero, because the recipe name isn't in the list it checks!

This happens because findtext searches for text within a text string. You want to find a specific element within a list. For that, you need 'Find()'.
mob/verb/Find_rec(t as text)
if(RecList.Find(t)
world << "Found [t]"
else
world << "Nope, not there."


A couple of other issues:
for(N.ingredients)

Im assuming you are wanting to cycle through the elements in your ingredients list here, but I'm actually surprised that isn't kicking out some kind of error, either compile time or runtime. As it is, you are essential saying 'for("The Recipe")', which I'm assumming must be working out to be 'for(1)' and running the enclosed statement one time. *shrug*

What you need to do is cycle through the elements of the list, much as we did when outputting the contents of the RecList list.
for(var/V in N.ingredients)
N.ing += "<li>[V]"


Also, the input() proc uses 'usr' as it's default first argument. You don't want that in a proc, so send 'M' as the first argument instead.
var/value = input(M, "Input Value") as null|text
In response to Flick
mob/verb/Find_rec(t as text)
if(RecList.Find(t)
world << "Found [t]"
else
world << "Nope, not there."


If I remember correctly, it either says RecList.Find is an undefined proc, or it doesn't ask you to input anything, it just says found.

Then I changed it to
mob/verb/Find_rec()
var/t = input("What recipe are you looking for?", "Recipe Search") as text //I had to get rid of the "M," for the time being because I'm logged in as guest, and it was giving me errors.
if(RecList.Find(t))
world << "Found [t]"
else
world << "Could not find [t]. Here are all the recipes:"
for(var/V in RecList)
world << V

I get "RecList.Find is an undefined proc"
I tried changing Reclist.Find to "findtext(Reclist, t)" and it always outputs false and shows "V" as OK every time, even if that's not what I name my recipe.
In response to Dragon of Ice
*bump*
In response to Dragon of Ice
Dragon of Ice wrote:
I get "RecList.Find is an undefined proc"

Instead of:
var
RecList = list()

try using:
var
list
RecList = list()

Hopefully that will fix your problem with RecList.Find().
In response to Jon88
Worked, thanks!