ok, so my wife has been looking up and down for a full-game version of Suikoden 2's cooking competition, and I've been trying to design one to no avail.
For those who've not had the pleasure of playing Suikoden 2, here's how it works:
You get recipe cards which allow you to make a basic recipe (let's say, sandwich)
You can then add a condiment (optional) to make a variation on the base ingredient (so, sandwich + tomato = BLT, or Hamburger)
Finally, this meal is judged, by appetizer, main course, or dessert, by a panel of judges who have favourite foods, foodstyles, or various dietary restrictions.
I've got the first half done - a simple synthesis script will manage that, allowing me to put "sandwich" as an item, finally, I can have the judges react according to what item is in the inventory (which, unfortunately, limits the player to making hamburgers only for main course, instead of erronously putting them as a dessert).
The hard part is: if Judge = 1 & Item = 1, then add 5 to variable "points". Basically, I need to write millions of events for every possible scenario.
Is there an easier way to do this? like, a script with notetags or something, that gives me basically what I need?
Make a hash of what each judge will give for each dish, so:
judge_1 = { 1 => 5, 2 => 4, 3=> 10 }
judge_2 = { 1 => 2, 2 => 10, 3 => 7 }
etc.
And then in your event, do
$game_variables[id for points] += judge_1[item id]
With this method you should only need a branch for each item.
Edit: Here's a very simple complete implementation with two judges and one item coded:
judge_1 = { 1 => 4, 2 => 5, 3 => 6 }
judge_2 = { 1 => 3, 2 => 6, 3 => 10 }
if $game_party.has_item?($data_items[1])
$game_variables[1] += (judge_1[1] + judge_2[1])
end
small nitpick, it should be
$game_variables[id for points] += (judge_1[item id] || 0)
Otherwise it would try to convert nil to Fixnum for item ids not in the hash and crash.
I live on the edge, lavra: error checking is for losers. 😛
I was going to suggest a solution with arrays, but Trihan's solution is probably better, so use it. 🙂
BTW, if you're looking for a game based on that minigame and you have RPG Maker 3, there's one with a lot of personality called "Pavilion Iron Chef". It's not my game, but I actually appear as one of the judges!!
@ Trihan ok, I'm not sure what you mean by a hash - is it, like, something I put into the comment box of each item, or do I make a new page on scripts for it?
also, I'm not sure what the numbers in the curly braces mean: for 1=>4, does that mean item #1 gets 4 points, or the item coded with this gets 4 points, but only in the first course?
I'm still relatively new to RPG maker, and very new to Ruby, so I wanna make sure I get this as accurate as possible.
@ Wavelength: my wife has wanted this since she started playing Suikoden 2 - I'll find an RTP package and install it just for this game if I have to.
You don't need to put anything in the comments for this. It's all handled within the hash, which is this:
judge_1 = { 1 => 5, 2 => 4, 3=> 10 }As you suspected, the hash can be read like "judge 1 gives item #1 5 points, item #2 4 points and item #3 10 points".
what is the hash, though? where do I find it? I know just enough code to know it's not past a hashtag (because they get ignored), but I have no idea where to put these lines of code
This would be a complete script that, given the id of the item to judge, calculates the combined points of all judges:
module JUDGES POINTS = [ {1 => 10, 2 => 5, 3 => 1}, {5 => 10, 3 => 5, 2 => 1} ] def self.get_points(item_id) POINTS.map{|judge| judge[item_id] || 0}.reduce🙂+) endend
The construct labeled "POINTS" is an array (recognized by "[...]") containing a number of hashes ("{...}"). Each hash stands for a judge and contains pairs in the form of "item id => points". The script is called with:
JUDGES.get_points(1)Which would give you 10, since judge #1 (the first hash in the array) gives 10 points and judge #2 gives 0.
and this would be transferrable with multiple judges, right?
say I wanted 9 judges, but only 3 judges to be randomly selected from that pool of 9 - I can just to script calls based off what the RNG gives me for judges.
so, Judge 1 would be called a RNG (1...3), and if it picks 3, the script call for that judge...
hmmm....
if all I need for the script is the sample you've given me, and the script calls earlier in the thread, I might be able to actually complete this, instead of leaving it at the wayside due to overwhelming complexity, like I have been...
You can add additional judges and points easily be adding new elements to the array / the hashes inside it. You should note, though, that the first entry in an array is indexed with 0 instead of 1.
The get_points method would need to be modified if you only want to pick some judges and not all, since in its current state it simply collects the points given from all judges, adds them up and returns that value.
for simplicity's sake, since I see you guys using judge_1, as I assume that's proper syntax, is judge_[1] proper? basically pulling a judge number out of a selected variable?
judge_1 is simply a name Trihan used for a variable. If you take a look at this line from my script:
POINTS.map{|judge| judge[item_id] || 0}.reduce🙂+)it does the following:
1) Take the array POINTS and iterate over every element in it (.map)
2) Reference each of those elements by the name "judge" (|judge|)
3) Get the points assigned to the given item id, or 0 if that item doesn't exist in the hash referenced by "judge" (judge[item_id] || 0)
4) .map is finished and returns an array containing numbers.
5) Those numbers are added up to determine the overall score (.reduce🙂+))
/edit: If you want to pick 3 random judges from the list you could modify the method like this:
POINTS.sample(3).map{|judge| judge[item_id] || 0}.reduce🙂+)
The method ".sample(3)" returns 3 random elements from an array, avoiding duplicates. Since we only have 2 elements (judges) in my example, it would return both.
ok, I'll have to play with this a bit and get a feel for it - many thanks thusfar, and I'll be back if I'm having issues with getting it to work how I want it to.