SmashLib: Expected results from smashing

Theraze

Active member
Attached is a tweaked version of the post 13 SmashLib, that fixes the warnings/errors from return/break in the switches.
 

Attachments

  • SmashLib.ash
    11.3 KB · Views: 173

Winterbay

Active member
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:
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;
	}
}

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...
Also, it does not warn on the bogus return values I added to places that definitely never will get reached.
 
Last edited:

Theraze

Active member
Yeah, sorry... tried to explain where the problems were... it's where it was returning and breaking after the returns in the switches. I had one similar (continue/break) in EatDrink. :)
 

rlbond86

Member
So I know this thread is old, but there is a bug in get_smash_yield():

Code:
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;
}

The bug is noted above. To find the expected yield of each thing, the line marked above should actually be


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:

Code:
> ash get_related($item[armgun],"pulverize");

Returned: aggregate int [item]
twinkly nuggets => 2000000
twinkly wad => 500000

I'm not sure where else this bug occurs, because I only use a few functions.
 
Last edited:

Winterbay

Active member
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.
 

Attachments

  • SmashLib.ash
    10.8 KB · Views: 346
Top