This wiki is a read-only version of the Stardew Valley Wiki. The official editable wiki maintained by ConcernedApe can be found at stardewvalleywiki.com

Template talk:Artisan

From Stardew Valley Wiki
Jump to: navigation, search
This talk page is for discussing Template:Artisan.
  • Sign and date your posts by typing four tildes (~~~~).
  • Put new text below old text.
  • Be polite.
  • Assume good faith.
  • Don't delete discussions.

Incorrect Values

This template is displaying incorrect base Juice values for Amaranth, Cauliflower, Corn, Fiddlehead Fern, Kale, Parsnip, and Radish; and incorrect base Wine values for Rhubarb and Strawberry. I haven't tested quality wine or juice.

I removed the truncation before calling Template:Qualityprice for juice, and it fixed a couple of juices, but not all of them. I haven't removed the truncation for wine, fearing it would do more harm than good.

I don't see how to fix this with the mediawiki syntax we have now. trunc() is supposed to be the same as casting to (int), but I'm not sure it actually is. Even if it is the same as casting to (int) in php, is that the same as casting to (int) in C# (as the game does)? Help? margotbean (talk) 19:30, 23 February 2017 (UTC)
p.s. I'm referring to the Artisan Profession price (pro=1), not the Artisan Base Price. Artisan Base Prices are correct! margotbean (talk) 19:39, 23 February 2017 (UTC)

Do you happen to have a list of correct Profession prices handy? Nnnes (talk) 22:51, 23 February 2017 (UTC)
For the Juices I mentioned above, the wiki value (see the Vegetables page) is 1 more than the value displayed on the shipping screen in-game. For Wine, the wiki value (see Fruits) is one less than the value displayed in-game. margotbean (talk) 23:07, 23 February 2017 (UTC)
Okay. This is a mess; not just my post here, but the whole deal. The important bits are bold. Sorry if any of this is just restating what you already know.
Here are the "fixes" I came up with. I'm not familiar with Mediawiki syntax for math (or function calling or anything useful really), but this pseudocode should be understandable. round2(n) rounds n to two decimal places [round2(2.71828) => 2.72]; if Mediawiki can't do that, I can come up with some other ugly expression that will do the trick if necessary. I assume trunc(n) removes everything after the decimal point.
Fruit wine: BP = Base Price; Artisan Profession price = trunc(round2(BP * 3 * 1.4)) [= trunc(round2(BP * 4.2))].
Vegetable juice: BP = Base Price; Artisan Profession price = trunc(round2(BP * 3.15) - 2 * (round2(BP * 3.15) - trunc(round2(BP * 3.15))))
Explanation if you're interested: Floating point numbers can't always be exact; this is a well-known problem in most programming languages. Here, a couple of the fruit values are problematic—for strawberries, 120 * 3 * 1.4 is, to a computer working in binary, 503.99999999999994, not the 504 you would get from a calculator. The easy solution is to round out the error; because none of the multipliers go past the hundredths place, rounding to the nearest hundredth won't lose any accuracy. Any other cases elsewhere where a value is being multiplied by a decimal should also be rounded to avoid this kind of issue. (Incidentally, because they're all multiples of 5, none of the current fruit values produce "bad" floats when multiplied by 4.2 [= 3 * 1.4]. However, plenty of other values do, so I recommend the rounding solution here in case new fruits are introduced.)
It gets a lot worse with the vegetable juices. What appears to be happening is that any final value that doesn't come out to be a whole number is truncated and then decremented by 1, while values that are whole numbers are left alone. This is very strange and likely unintended behavior; I might ask ConcernedApe about it. In the meantime, the above expression is about the best I can do without being able to store variables or using if/then statements. Perhaps someone else can improve it?
The two formulas above produce the correct Artisan Profession base prices for all fruits and vegetables. I have not checked quality prices, so I don't know whether this decrementing funny business applies to them.
This would be a lot easier if we didn't care about an error of 1 in a couple prices, but where's the fun in that? :D
Nnnes (talk) 05:20, 24 February 2017 (UTC)
You rock for doing all that analysis, I can't thank you enough! For now, it's late, so I'm going to look at it in more detail tomorrow, but I wanted to give you the decompiled code so you can have a chuckle (did someone say mess??)
Quality = 0,1,2,4 (normal, silver, gold, iridium)
Wine: (int)((float)((int)((float)(BP * 3) * (1f + (float)Quality * 0.25f)))*1.4f)
Juice: (int)((float)((int)((float)(int)((double)BP * 2.25) * (1f + (float)Quality * 0.25f)))*1.4f)
By the way, I didn't dig up those formulas until after I had given up on fixing this today. Or perhaps they are what caused me to give up. In any event, I really appreciate your doing all that analysis! margotbean (talk) 07:58, 24 February 2017 (UTC)
I was going to make some comments on that code, but you know what, I'll just let it express itself without being subject to judgment.
These should be equivalent to the game source code, I hope:
Wine: trunc(round2(trunc(trunc(BP * 3) * (1.0 + Quality * 0.25)) * 1.4))
Juice: trunc(round2(trunc(trunc(BP * 2.25) * (1.0 + Quality * 0.25)) * 1.4))
As a bonus, these highlight my lack of knowledge. Apparently 120.0f * 3.0f * 1.4f really is exactly 504.0f in C# (and other C variants? C++ at least), while it isn't in Mediawiki-language and Ruby, where I did my testing. I do know that multiples of 0.25 are exact numbers in binary and so don't require rounding. Cheers! —Nnnes (talk) 14:59, 24 February 2017 (UTC)
This works without needing rounding:
Wine: trunc(trunc(trunc(BP * 3) * (1.0 + Quality * 0.25)) * 14 / 10.0)
Juice: trunc(trunc(trunc(BP * 2.25) * (1.0 + Quality * 0.25)) * 14 / 10.0)
I thought I'd try changing the template myself, but I don't know how to perform operations after calling Qualityprice. It does make a difference; if Qualityprice is calculated after the profession multiplier, many of the quality juice prices will be wrong. —Nnnes (talk) 18:16, 24 February 2017 (UTC)
Hmm... yeah... you can't perform calculations after the call to QualityPrice. A solution could be to replace the call to QualityPrice with all the code from QualityPrice, but chopped up accordingly. Or, this template could be replaced altogether... it's used in 3 places: Fruits, Vegetables, and Template:Infobox. Template:Infobox is ...um... a beast. A huge beast with a lot of complexity and way too many pipe characters. I dunno... I only know that I would need a good night's sleep before even thinking about tackling it. If you want to experiment, please do! At least we have the correct calculations now (thanks to you).  :D
p.s. No offense to ConcernedApe, but that code... what you said. ;) margotbean (talk) 19:07, 24 February 2017 (UTC)