Attached is a tweaked version of the post 13 SmashLib, that fixes the warnings/errors from return/break in the switches.
What did you do to get those? As far as I can see every function in that script has a return value at the end of it (some of them are there in order to fix the thing that the update of mafia fixed, but that's beside the point as they should never be reached anyway), unless I added that to my local copy without updating the thread which I don't think I did.
Edit: Ok, so missing one update made me miss the .jar that added this feature
However it appears to not work properly, or could someone explain to me why the code warns on this:
The warnings start at "case $item[useless powder]", but I'm pretty certain that part of the code isn't unreachable. At least when calling the script with "antique spear" or "sponge pants" I get the expected result back...Code:foreach thing in result { switch(thing) { case $item[twinkly nuggets]: case $item[twinkly wad]: returnmap["twinkly"] = 1.0; break; case $item[cold nuggets]: case $item[cold wad]: returnmap["cold"] = 1.0; break; case $item[hot nuggets]: case $item[hot wad]: returnmap["hot"] = 1.0; break; case $item[sleaze nuggets]: case $item[sleaze wad]: returnmap["sleaze"] = 1.0; break; case $item[stench nuggets]: case $item[stench wad]: returnmap["stench"] = 1.0; break; case $item[spooky nuggets]: case $item[spooky wad]: returnmap["spooky"] = 1.0; break; case $item[useless powder]: returnmap["useless"] = 1.0; return returnmap; break; case $item[epic wad]: returnmap["epic"] = 1.0; return returnmap; break; case $item[sea salt crystal]: returnmap["sea salt"] = 1.0; return returnmap; break; case $item[ultimate wad]: returnmap["ultimate"] = 1.0; return returnmap; break; case $item[sugar shard]: returnmap["sugar"] = 1.0; return returnmap; break; case $item[chunk of depleted Grimacite]: returnmap["depleted Grimacite"] = 1.0; return returnmap; break; case $item[wad of Crovacite]: returnmap["Crovacite"] = 1.0; return returnmap; break; case $item[BRICKO brick]: returnmap["BRICKO"] = 1.0; return returnmap; break; } }
Also, it does not warn on the bogus return values I added to places that definitely never will get reached.
Last edited by Winterbay; 03-05-2012 at 07:56 AM.
My scripts:
Best sushi for Profit
Winterbay's Helpful Automatic Monsterbasher (WHAM)
Scripts maintained by me:
Autobasement
Smashlib
A small programmer joke:
Wife: Honey, please go to the market and buy 1 bottle of milk. If they have eggs, bring 6.
The man came back with 6 bottles of milk.
Wife: Why did you buy 6 bottles of milk.
Man: Because they had eggs...
The 6 Stages of Debugging: 1 )That can't happen. 2) That shouldn't happen. 3) Hmmm, weird. 4) Why does that happen? 5) Oh, I see. 6 )How did that ever work?
All programs can be optimized, and all programs have bugs; therefore all programs can be optimized to one line that doesn’t work. /Bob Fitch, Blizzard
A "break" immediately after a "return" is unreachable.
In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)
Ahh oh,thanks. I missed that due to the variable name being returnmap...![]()
My scripts:
Best sushi for Profit
Winterbay's Helpful Automatic Monsterbasher (WHAM)
Scripts maintained by me:
Autobasement
Smashlib
A small programmer joke:
Wife: Honey, please go to the market and buy 1 bottle of milk. If they have eggs, bring 6.
The man came back with 6 bottles of milk.
Wife: Why did you buy 6 bottles of milk.
Man: Because they had eggs...
The 6 Stages of Debugging: 1 )That can't happen. 2) That shouldn't happen. 3) Hmmm, weird. 4) Why does that happen? 5) Oh, I see. 6 )How did that ever work?
All programs can be optimized, and all programs have bugs; therefore all programs can be optimized to one line that doesn’t work. /Bob Fitch, Blizzard
So I know this thread is old, but there is a bug in get_smash_yield():
The bug is noted above. To find the expected yield of each thing, the line marked above should actually beCode:float [item] get_smash_yield(item it) { float [item] resultf; float sum = 0; int[item] resulti; if (!is_smashable(it)) return resultf; string tier = get_smash_tier(it); float [string] element_type = get_smash_element(it); resulti = get_related(it,"pulverize"); foreach thing in resulti { sum = sum + resulti[thing]; } foreach thing in resulti { resultf[thing] = resulti[thing] / sum; // BUG HERE } return resultf; }
resultf[thing] = resulti[thing] / 1000000.0; // This is correct
This properly accounts for multiple returns. In addition, the computation of the variable "sum" is unnecessary.
For example, the item "Armgun" yields 4 nuggets 50% of the time, and 1 wad 50% of the time.
Working out the math, that means that the average yields should be:
E(#Twinkly nuggets) = 0.5*4=2
E(#Twinkly wads) = 0.5*1=0.5
This is properly reflected by the get_related ash function:
I'm not sure where else this bug occurs, because I only use a few functions.Code:> ash get_related($item[armgun],"pulverize"); Returned: aggregate int [item] twinkly nuggets => 2000000 twinkly wad => 500000
Last edited by rlbond86; 05-01-2012 at 04:16 PM.
This version fixes errors due to element now being disallowed in foreach-loops (as it should really) and the above mentioned bug that was probably introduced when I went from loading the map to using get_related.
My scripts:
Best sushi for Profit
Winterbay's Helpful Automatic Monsterbasher (WHAM)
Scripts maintained by me:
Autobasement
Smashlib
A small programmer joke:
Wife: Honey, please go to the market and buy 1 bottle of milk. If they have eggs, bring 6.
The man came back with 6 bottles of milk.
Wife: Why did you buy 6 bottles of milk.
Man: Because they had eggs...
The 6 Stages of Debugging: 1 )That can't happen. 2) That shouldn't happen. 3) Hmmm, weird. 4) Why does that happen? 5) Oh, I see. 6 )How did that ever work?
All programs can be optimized, and all programs have bugs; therefore all programs can be optimized to one line that doesn’t work. /Bob Fitch, Blizzard