How do i make a crafting table
I've been seeing how to make a crafting recipe but not how to make a crafting table please help.
This question is far too vague to be answered, please specify exactly what it is you want help with, creating an object for the "table" in the scene, interacting with it to trigger the recipe UI, or the recipe UI itself.
no i just want to now how to make the table and do crafting with it
Please submit this sort of post as a reply ins$$anonymous$$d of a new answer. Also your question is still far to vague to be answered. "how to make the table and do crafting with it" Is not specific enough to get reasonable answers that will be of use. You need to break the problem down into smaller parts and work out which specific smaller part it is you need to tackle first.
Answer by Statement · Nov 11, 2015 at 10:16 PM
I guess you mean a crafting table, similar to the crafting table in Minecraft?
You'd create patterns for items. Then you test if the pattern exist in the table. If multiple patterns exist in the table, choose the biggest pattern (for example a door may be 2x3 and a box may be 2x2 - the door trumps the box).
You can see the solution to another answer I provided, which contain a basic pattern matching algorithm.
Then you could define patterns for your recepies:
int[,] boxPattern = {
{ 1, 1 },
{ 1, 1 },
};
int[,] doorPattern = {
{ 1, 1 },
{ 1, 1 },
{ 1, 1 },
};
int[,] chestPattern = {
{ 1, 1, 1 },
{ 1, 1, 1 },
};
...For example (1 could mean "wood" or whatever material you want, it's up to you do decide).
Then you could bind patterns to items.
// To give patterns a name, basically...
class Recepie
{
public string name;
public int[,] pattern;
}
And add other information you want to include in your crafting process, it's up to you.
Finally, you can test it as HasPattern(table, recepie.pattern)
to see if you got a match.
If you do, save the result and try the next recepie. The "biggest" recepie will then be selected as the item the player wanted to craft, and so you can craft that item Craft(recepieWithLargestPattern.name)
Note that the example would match both box, door and chest if the player put all ones in the table:
1, 1, 1
1, 1, 1
1, 1, 1
The above would match box, door and chest. Door and chest are equally large so the algorithm would have picked either door or chest, but we can clearly see it's undesirable to do either (I guess). So you may want to either add rules that everything else must be blank, or specify blanks in the pattern.
int[,] boxPattern = {
{ 0, 0, 0 },
{ 0, 1, 1 },
{ 0, 1, 1 },
};
int[,] doorPattern = {
{ 0, 1, 1 },
{ 0, 1, 1 },
{ 0, 1, 1 },
};
int[,] chestPattern = {
{ 0, 0, 0 },
{ 1, 1, 1 },
{ 1, 1, 1 },
};
However this solution would work, it would mean you'd have to explicitly define every possible permutation of the table, which feel tedious. You could ins$$anonymous$$d modify the example algorithm I linked to optionally require "all other slots must be 0".
Perhaps an improvement for readability when designing the patterns would be to use characters ins$$anonymous$$d of numbers to represent type.
'w', 'w'
'w', 'w'
This would perhaps make it easier to understand that it should match wood.
'*', 'w', '*'
' ', 'w', ' '
This would perhaps make it easier to understand you want to match a 2 slot tall wooden shaft, with two arbitrary recepie types.
Obviously, if you want to get serious about it, you could create your own kind of DSL or pattern style with parsers to help you solve the task
pattern.Add("*W*");
pattern.Add(" W ");
Or even more complex
pattern.Add($$anonymous$$atch.Any, $$anonymous$$atch.Type("Wood"), $$anonymous$$atch.Any);
pattern.Add($$anonymous$$atch.Blank, $$anonymous$$atch.Type("Wood"), $$anonymous$$atch.Blank);
And use types with rich logic, basically program$$anonymous$$g the pattern recognition task.
Thank you i'm trying to make a good survival game and that really helped me thank you.